• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

more about nested class topics

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read Corey's SCJP tiplines on inner class topics, there are 4 types of inner class: inner, nested, anonymous, local. But the terms in Sun Certified Java Programmer Pre-Exam Essentials seem a little different: non-static nested, static nested, amonymous, non-static nested in method's scope. I am not very sure of the terms and concepts that i catch, so i write the code below for REVIEWs if i have made mistakes. Is this enough for the exam? THANK YOU.
Yours,
William.

[ October 17, 2006: Message edited by: William Yan ]
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi William,

Below is the explanation . I hope you will understand clearly after reading this . if you still have any confusion please let me know..


Inner or non-static nested : :

the term Inner here to represent inner classes that are not :

Static
Method-local
Anonymous

Example::

class MyOuter {
private int x = 7;
// inner class definition i.e not static
class MyInner {
public void seeOuter() {
System.out.println("Outer x is " + x);
}
} // close inner class definition
} // close outer class


Nested or static nested ::

Static nested classes referred to as static inner classes, but they really aren't inner classes at all, by the standard definition of an inner class.
While an inner class (regardless of the flavor) enjoys that special relationship with the outer class (or rather the instances of the two classes share a relationship), a static nested class does not.

Actually there is no static class at all.it’s like a static member of a class in which it’s declared.
Example :

class BigOuter {
static class Nested { }
}



Amonymous Class ::


inner classes declared without
any class name at all (hence the word anonymous).

you can define these classes not just within a method, but even within an argument to a method.

Example ::

class Popcorn {
public void pop() {
System.out.println("popcorn");
}
}
class Food {
Popcorn p = new Popcorn() {
public void pop() {
System.out.println("anonymous popcorn");
}
};
}


Laocal or non-static nested in method's scope ::

Any class i.e declared within the scope of a method .even though we can have these classes in loops any block etc.

Example ::

class MyOuter2 {
private String x = "Outer2";
void doStuff() {
class MyInner {
public void seeOuter() {
System.out.println("Outer x is " + x);
} // close inner class method
} // close inner class definition
} // close outer class method doStuff()
} // close outer class



Regards…..
 
William Yan
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, raunak.
The concept seems the same in your code and mine.

Regards,
William
 
reply
    Bookmark Topic Watch Topic
  • New Topic