aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes can an inner class extends the outer class? 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 "can an inner class extends the outer class?" Watch "can an inner class extends the outer class?" New topic
Author

can an inner class extends the outer class?

Simo Hayha
Greenhorn

Joined: Jul 02, 2002
Posts: 19
thanks!
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Why don't you try first with a little piece of code and then come back if you still have doubts? Remember this: Practice is your best companion on your learning path!!


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Simo Hayha
Greenhorn

Joined: Jul 02, 2002
Posts: 19
sorry, i use a public computer,and there is no jdk in the computer,so i can not test the code.
thank you all the same!
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Ok then (how would I know ) here is a piece of code which shows you that an inner class may extend its enclosing class:

Output is:
hello from Outer.Inner

[ August 21, 2002: Message edited by: Valentin Crettaz ]
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
It is legal. However I wouldn't use it in a program.
See the opinion of Roseanne


SCJP2. Please Indent your code using UBB Code
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
Me too. Unless I need GUI event handlers, I wouldn't otherwise touch an inner class with a stick.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
It isn't what I mean. I think inner classes are really useful as Bruce Eckel shows in Thinking in Java. But to be 100% safe, you cannot extends from the outer, or expect that something like the tenth inner class is going to make happy the JVM in all ocassions.
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
IMHO inner classes break encapsulation the same way friend classes do in C++ so I'm really not convinced...
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
In Java inner classes can serve as call backs. Also they allow a kind-of multiple inheritance. But they are save, in the sense that you cannot send to an inner class other messsages apart from those allowed by its type.
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Hi there:
The inner classes can be used to implement multiple inheritance in Java. They provide
for inheriting from multiple concrete class (as well as interfaces and abstract classes) which is not possible with regular classes. But creating
an inner class that extends the outer class, does not
seem like solving any real world problems...
Thanks
Barkat
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can an inner class extends the outer class?