aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes more about nested class topics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "more about nested class topics" Watch "more about nested class topics" New topic
Author

more about nested class topics

William Yan
Ranch Hand

Joined: Sep 26, 2006
Posts: 69
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 ]

Java is better and better, yet bitter and bitter.
Maneessh saxena
Ranch Hand

Joined: Oct 03, 2006
Posts: 125
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…..


SCJP 1.4, SCWCD 1.5
William Yan
Ranch Hand

Joined: Sep 26, 2006
Posts: 69
Thank you, raunak.
The concept seems the same in your code and mine.

Regards,
William
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: more about nested class topics