This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes inner class - subclass???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "inner class - subclass????" Watch "inner class - subclass????" New topic
Author

inner class - subclass????

Nasir Khan
Ranch Hand

Joined: Nov 04, 2000
Posts: 135

This statement is from jxam:
"An inner class can actually be a subclass of the outer class"
Please tell me if it's correct or not.
Junaid Bhatra
Ranch Hand

Joined: Jun 27, 2000
Posts: 213
Yes an inner class can be a subclass of the outer class. You can write a simple test program for yourself, compile it and see the results.
Nasir Khan
Ranch Hand

Joined: Nov 04, 2000
Posts: 135
Thanks Junaid
I tried with this code
__________________________
class out {
out(){System.out.println("out constructor");}
void method(){
class inner extends out{
inner(){System.out.println("I'm in inner constructor"); }
}
new inner(); }
}

class tes extends out{
public static void main(String [] arg){
new tes().method();}
}
_________________________________
As expected tes().method(); invokes out's constructor twice and inner's costructor once.
Does anyone know any advantage of extending the outer class to inner class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inner class - subclass????
 
Similar Threads
Overriding methods
are this two statements about INNER class is true?
Inner class
Anonymous inner class
How to use Abstract inner classes ?