Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Glenn Duncan   on Apr 08 In Java Category.

  
Question Answered By: Sophie Campbell   on Apr 08

the difference  is in access privilege to class  members (variable and methods)

java tutorial at following address has answered your question  like this:
java.sun.com/.../nested.html

nested  class is a member of its enclosing class. non-static  nested classes (inner classes) have access to other members of the enclosing class, even if they are declared private. static  nested classes do not have access to other members of the enclosing class. As a member of the OuterClass, a nested class can be declared private, public, protected, or package private. (Recall that outer classes can only be declared public or package private.)

if you need a class that is only used by one other class (like an internal data structure in an special algorithm) then you can use nested class.
if you need a class that is used by other class and must have access to its parent variables, like introducing an event handler that modifies some member variables, then you use inner classes.

Share: 

 

This Question has 5 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on nested class Or get search suggestion and latest updates.


Tagged: