Describe inner classes in java, JAVA Programming

Describe Inner Classes in java?

An inner class is a class whose body is described inside another class, referred to as the top-level class. For instance:
public class Queue {

Element back = null;

public void add(Object o) {

Element e = new Element();
e.data = o;
e.next = back;
back = e;

}

public Object remove() {

if (back == null) return null;
Element e = back;
while (e.next != null) e = e.next;
Object o = e.data;
Element f = back;
while (f.next != e) f = f.next;
f.next = null;
return o;

}

public boolean isEmpty() {
return back == null;
}

// Here's the inner class
class Element {

Object data = null;
Element next = null;
}

}
Inner classes may also holds methods. They may not contain static members.

Inner classes within a class scope can be public, private, protected, final, abstract.
Inner classes can also be used inside methods, loops, and other blocks of code surrounded by braces ({}). Such a class is not a member, and thus cannot be declared public, private, protected, or static.

The inner class has access to all the methods and fields of the top-level class, even the private ones.
The inner class's short name might not be used outside its scope. If you absolutely must use it, you can use the fully qualified name instead. (For instance, Queue$Element) Therefore, if you require doing this you should almost certainly have made it a top-level class instead or at least an inner class inside a broader scope.

Inner classes are most useful for the adapter classes needed through 1.1 AWT and JavaBeans event handling protocols. They permit you to implement callbacks. In most other languages this would bo done along with function pointers.

Posted Date: 5/16/2013 2:44:37 AM | Location : United States







Related Discussions:- Describe inner classes in java, Assignment Help, Ask Question on Describe inner classes in java, Get Answer, Expert's Help, Describe inner classes in java Discussions

Write discussion on Describe inner classes in java
Your posts are moderated
Related Questions
This project simulates a remote procedure call on a client-server architecture. You will create both the client and the server. The server will maintain a linked list. It must N

1) Write a function that uses recursion that converts a decimal number to octal (base 8). The function should accept a single integer and return a String containing the base 8 equi

Write HTML and JavaScript code which displays a textbox and button on a web page? While user enters text in the text box and clicks the button it displays in that text in the m

Platform independence is the key feature of Java during runtime. Syntax of java is same to the popular object oriented languages such as C and C++. Java program can eliminate most

What is the Comparable interface? Comparable interface is used to sort arrays and collections of objects using collections.sort() and java.utils. Objects of the class implement

Describe about basic java programming language? 1. Study the Java programming language: its syntax, patterns, idioms, and styles. 2. Become comfortable along with object orien


Assistance for JSON authentication problem RSS/AOL/Android The key problem we face is how to authenticate afterward the user logged in the webview as well as then parse the JSON

The purpose of this assignment is to give you practice working with one dimensional arrays. It will also introduce you to one of the oldest mathematical algorithms in the world. No

What is an intelligent system? Intelligent system is a SW programs or SW and HW systems designed to perform complex tasks employing strategies in which mimic some aspect of hum