File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "inner class - subclass????" Watch "inner class - subclass????" New topic

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.
It is sorta covered in the JavaRanch Style Guide.
subject: inner class - subclass????