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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Inner Nested Classes 
 

Non-static nested classes are slightly different from static nested classes, a non-static nested class is actually

 

Inner Nested Classes

                         

Non-static nested classes are slightly different from static nested classes, a non-static nested class is actually associated to an object rather than to the class in which it is nested.

Any member of the inner nested class is not a part of its outer class while its source code is in the class definition. Non-static members of a class specify the requirements of objects created from that class. Every object has a copy of the nested class that belongs to the outer class. The same copy should access all the methods and instance variables of that object.

Methods and variables of an inner class can be access directly by the object of outer class. The figure given below illustrates it logically.

An InnerClass Exists Within an Instance of OuterClass.

Lets try to explain the concept of inner nested class with the help of an example. There is an inner class company exists within an outer class Info. The class Info is to be referred as non-static nested class. The class Info invokes the method of the class Company with the help of the object of the class Company.

Here is the code of the Example :

Info.java

import java.lang.*;

public class Info{

  static String compName="Rose India";

      public static class Company{

    int time=10;

    void showinfo(){

     System.out.println("Our Company Name : "+compName);

     System.out.println("The time of the company : "+time);

     }

   }

   public static void main(String[] args){

      Info.Company object = new Info.Company();

      object.showinfo();

        }

  }

Here is the output of the Example :

C:\roseindia>javac Info.java

C:\roseindia>java Info
Our Company Name : Rose India
The time of the company : 10

Download this Example:

                         

» 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.