• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

To Bert Bates(Inner class Significance)

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22789
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the reply. But is there any significant purpose for making inner classes abstract ot interface.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
reply
    Bookmark Topic Watch Topic
  • New Topic