Describe inner classes in java, JAVA Programming

Assignment Help:

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.


Related Discussions:- Describe inner classes in java

Converting strings to numeric primitive data types, Converting Strings to N...

Converting Strings to Numeric Primitive Data Types To convert a string which is containing digits to a primitive data type, wrapper classes can help. parseXxx method can be u

Heap and Stack memory allocation in java, Each time an object is started in...

Each time an object is started in Java it goes into the area of memory named as heap. The primitive variables like double and int are allocated in the stack, if they are local inst

Write a xhtml document with java script, Write an XHTML document that uses ...

Write an XHTML document that uses JavaScript code to do the following.  The user is first prompted for a word and then for a possible prefix for that word.  If the prefix is not an

Luminous Jewels, Byteland county is very famous for luminous jewels. Lumino...

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

How much cpu time does an applet get, How much CPU time does an applet get?...

How much CPU time does an applet get? One of the few legitimate concerns about hostile applets is excessive use of CPU time. It is possible on a non-preemptively multitasking s

Idea for a project, I want to get some idea about how i can make a project ...

I want to get some idea about how i can make a project on "Free Lancer Teaching."

Data structure of different delimiters, In this experience you will make th...

In this experience you will make the neophyte Java programmer happy by solving, to a limited extent, an age-old problem in programming:  mismatched delimiters.  As we all know, eve

Packages and interfaces, what are the advantages of packages and interface?...

what are the advantages of packages and interface? why we use them? and what is the way of using packages and interfaces complete description with examples?

What do you understand by private and public class, What do you understand ...

What do you understand by private, protected and public? These are accessibility modifiers. Private is the most restrictive, whereas public is the least restrictive. There is n

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd