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
What are the advantages of multimedia presentations? Write any five. Multimedia presentation is a excellent tool for effective communication: Advantages: 1. Easy to make l

Define the key weakness of the web? the key weakness of the web is Initially web was designed only for humans to read not for computers to understand it.

How to Implementing the Cloneable Interface The java.lang.Object class contains a clone() method which returns a bitwise copy of the current object. protected native Object cl

The Struts tag libraries are: ? HTML Tags ? Logic Tags ? Template Tags ? Bean Tags ? Tiles Tags ? Nested Tags

What is bandwidth? In a general way Bandwidth is a capacity of communication channel of carrying data.

Explain Animate gifs? We can save 16 gif images of the previous instance in a single file in the form of an animated gif, and then used it in a regular tag to display a movi

A NEW Dynamic Website I have the subsequent requirement which needs to be designed in 30 days (Max). 1) Construct a website which is a dynamic, means allow me to change conte

What is an immutable object? An immutable object is one that we can't change once it's created. Steps involved in creation of an immutable object are: Make all of its data f

State about the JVM? JVM is the acronym which stands for 'Java virtual machine'. JVM provides execution environment. JVM isn't platform independent. JVM is Java

Java Programming 1. Discuss any five buzz words in Java. 2. Describe exception classes and also explain common exceptions in java. 3. Describe primitive and abstract data