Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Nested classes 
 

Here is another advantage of the Java, an object-oriented programming language that allows us to define a class within another class, such classes are known as nested classes.

 

Nested classes

                         

Here is another advantage of the Java, an object-oriented programming language that allows us to define a class within another class, such classes are known as nested classes. Inner classes can be either named or anonymous. We'll discuss about anonymous classes later in this section. A named inner class looks just like any other class, except that it is nested inside another class. ( It can even contain further levels of nested classes, but you shouldn't carry these things too far ).

Like the members of a class, a named inner class can be either static or non-static. A static nested class is part of the static structure of the containing class. It can be used inside a class that is used to create objects in the usual way. If it has not been declared private, then it can also be used outside the containing class, but when it is used outside the class, its name must indicate its membership in the containing class. This is similar to other static components of a class: A static nested class is part of the class itself in the same way as static member variables are the part of the class itself.

A simple nested class example is given below:

class OuterClass {
    ...expression...
    class NestedClass {
    ...expression...
    }
}

A static nested class has full access to the members of the containing class, even to the private members. This can be another motivation for declaring a nested class, since it lets a class to gain access to the private members of another class without making those members generally available to other classes.

There are two categories of nested classes, which are as under:
i)  Static classes
ii) Inner classes (Non-static)

                         

» View all related tutorials
Related Tags: c programming ide class data time template object fun io objects methods classes method vi exec new instance id ai

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.