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

Extending inner class

 
av bharathiraja
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to create a class that extends an inner class of another class. also kindly let me know the links/copies of mock exam.
 
Nandini Bhaduri
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is possible.
 
av bharathiraja
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried by extending a class with subclass residing at another class
like myclass extends myOuter.myInner{
public static void main(String a[])
{ }
}

class myOuter{

class myInner{

}
}
but it was throwing Class can'nt be resolved error at compile time.

Could you give me an example
[ December 22, 2006: Message edited by: av bharathiraja ]
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The inner class can not reached with out a outer class so inner class can not be inherited,If I am not wrong.However a static inner class can be inherited like

It is invalid to inherit the Inner class by its enclosing outer class.

The above code is invalid.
 
Andrea Z�rcher
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should differentiate between the following types of inner classes:

- (regular) inner class
- method-local inner classes
- anonymous inner classes
- static nested classes

If I�m not wrong, only static nested classes can be subclassed.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All of them can be subclassed except for anonymous classes.
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim,
Can you give an example of each of them.I tried but couldnt make it.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by av bharathiraja:
... Could you give me an example

 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Maneessh saxena
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sanjeev Kumar Singh:
The inner class can not reached with out a outer class so inner class can not be inherited,If I am not wrong.However a static inner class can be inherited like

It is invalid to inherit the Inner class by its enclosing outer class.

The above code is invalid.



hi Sanjeev,
you are in big confusion as you said ,"inner class can not be inherited". we can extend Inner classes as well.please try the code below.

class Outer{
class Inner{
}
}
class OuterDemo{
class InnerDemo ectends Outer.Inner{
public InnerDemo(){
Outer.super();
}
}
}

as InnerDemo class does not no which object to bind to so the non-default
constructor is necessary to intimate Outer class that it has an outer
object to bind to.
However this outer object problem is not arised if OuterDemo ectends Outer
class.in that case we need not use non-default constructor.

hope this will help .
if still confused please let me know.

Regards.
MAneesh Saxena
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Raunak for pointing out my errors.The thing I was trying is to extend a inner class by a top level class,which seems to be impossible.All the class which are extending an inner class are itself inner.
 
Maneessh saxena
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sanjeev Kumar Singh:
Thanks Raunak for pointing out my errors.The thing I was trying is to extend a inner class by a top level class,which seems to be impossible.All the class which are extending an inner class are itself inner.


hi again,

dear sanjeev we can also extend Inner classes by top level class.the thing is same again it requires the same non-default constructor to intimate Outer class that it has an outer object to bind to.

class Outer{
class Inner{
}
}
class OuterDemo extends Outer.Inner{
public OuterDEmo(Outer ob){
ob.super();
}
}

try above syntax it'll surely remove your confusion.

Regards
Maneesh Saxena
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic