File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can an inner class extends the outer class?

 
Simo Hayha
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks!
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
Simo Hayha
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is legal. However I wouldn't use it in a program.
See the opinion of Roseanne
 
Anthony Villanueva
Ranch Hand
Posts: 1055
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Me too. Unless I need GUI event handlers, I wouldn't otherwise touch an inner class with a stick.
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1055
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMHO inner classes break encapsulation the same way friend classes do in C++ so I'm really not convinced...
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 787
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic