Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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.

Java, Programming

  • Category:- Java
  • Reference No.:- M9547472

Have any Question?


Related Questions in Java

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assessment database and multithread programmingtasktask 1

Assessment: Database and Multithread Programming Task Task 1: Grade Processing University grading system maintains a database called "GradeProcessing" that contains number of tables to store, retrieve and manipulate stud ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As