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(); = o; = back;
back = e;


public Object remove() {

if (back == null) return null;
Element e = back;
while ( != null) e =;
Object o =;
Element f = back;
while ( != e) f =; = 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
Preventing Applet Based Social Engineering Attacks To help avoid this, Java applet windows are specifically labeled as such along with an ugly bar that says: "Warning: Applet W

Project Description: I want to build a camera application for android. By default android will add metadata for the image, for e.g.  Date, time, resolution, gps tag etc..In this

Create a class to implement the ArrayList collection. The name should be YourFirstNameArrayList; for example if I were creating the class then I would call it WaynesArrayList. Do

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

Using RMI, program a PONG game that enables two users to play against one another. Pong class: package graphics;/* * Copyright (c) 2006, Your Corporation. All Rights Reserved. */

The significant methods of ActionForm are: validate () & reset ().

What is Scope of Variable ? Space in that a variable is effective is called as the scope of a variable. In other words we can say area where that variable is available for the

The class TurtleQTwo extends Turtle by adding one new method, plus, which is specified below. (All other features of TurtleQTwo are the same as for Turtle.) method plus(n in

Can we use the constructor, instead of init(), to initialize servlet? Ans) Yes. Of course you can use the constructor instead of init(). There's nothing to stop you. But you sho

Question: (a) (i) Explain the concept of inheritance. Illustrate your answer with a suitable Java example. (ii) Java does not support multiple inheritance but does provide