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

Switch statement in javascript, If there exist multiple conditions, the swi...

If there exist multiple conditions, the switch statement is suggested. It is because only one expression gets evaluated depending on which control jumps directly to the respective

Design and implement online food delivery system, You are required to  desi...

You are required to  design & implement  online  food delivery  system  using Java RMI technology.  This involves writing both the server and the client program(s). Client programs

What is jsf life cycle and its phases, The series of steps followed by an a...

The series of steps followed by an application is known its life cycle. A JSF application typically follows six steps in its life. 1. Restore view phase 2. Apply request valu

What type of information can be stored in a database, What type of informat...

What type of information can be stored in a database? In a database we can store several types of informations like: • Numbers, Booleans, text • Sounds • Images • Video

Pogram must work on all realms and all ladders, Project Description: The...

Project Description: The program must work on all realms, all ladders, all cores (4x realms,2x ladders,2x cores) The program must be unpatchable and undetectable If patche

I need java expert with tomcat tuning experience, I need Java expert with t...

I need Java expert with tomcat tuning experience Project Description: Require a Java expert to fix memory issues with tomcat. Skills required: Java, Apache

I need the answer for this question as code, I earn .... Rs per month. if m...

I earn .... Rs per month. if mobile costs 20% of my earning. I will buy in cash. if costs more than 20%. I will buy in 3 months installments without interest. if costs more than 40

Convert string to super ascii, A string S is said to be "Super ASCII", if i...

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''''a''''-''''z'''') and

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