• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Innner Class

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
Can inner class be abstract?
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens when you compile the following?
<PRE>public class Test {
abstract class x{}
}</PRE>
 
Supree
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tony.
Got you.
Innner class can be abstract
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the inner class is an abstract one ,is it required that outer class shoud be declared as an abstract class. cos the non-static inner class is some thing like a class instance variable or method right?? ( ofcourse i got the answer that it need be!! am looking for any explanation !! thanks in advance)
 
Tony Alicea
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See my example above. I never post code like that without compiling it first. So if an inner class is abstract, the outer class doesn't have to be.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh Sorry there is typo there that's what i mean it " need not be".My question is why is it so ? . Normally if any one method of a class is abstract then class must be defined as abstract isn't it?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes - but that's just the relationship between methods and the class that contains them. There is no such rule for inner classes and the class that contains them.
The reason that abstract methods force the entire class to be abstract is to prevent the possibility that a class could be instantiated without an implementation of one of its methods. In the case of abstract inner classes, it is already impossible to instantiate the inner class (as soon as you call a constructor for it, you get "can't instantiate abstract class"). So there is no way to write any code that would successfully access any abstract (undefined) features, and additional "protection" (in the form of an additional rule) is unnecessary.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic