• Post Reply Bookmark Topic Watch Topic
  • New Topic

To Bert Bates(Inner class Significance)  RSS feed

 
Pradeep Kumar
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am preparing for the SCJP but i fount is interesing while i observed some scenarios. I am curious about these things and want to get my doubts cleared.Here are the some observations i could make out.

1. What is the sigmificance of a regular inner class which is abstract or an interface.
2. If i have a inner class which is abstract or an interface what is its significance outside the class, For ex:

public class Test {
public abstract class Inner{
}
}
class Test1 extends Test{
Test.Inner ob = new Test().new Inner();
}
Can i instantiate the inner class somehow in Test1.If yes what will be the syntax.
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No you can't. Nested abstract classes and interfaces are just like regular abstract classes and interfaces, and cannot be instantiated.

You could either create a "normal" subclass / implementation, or create an anonymous subclass / implementation:
Test.Inner ob = new Test().new Inner()
{
// implement abstract methods here
};
 
Pradeep Kumar
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply. But is there any significant purpose for making inner classes abstract ot interface.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!