Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Innner Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Innner Class" Watch "Innner Class" New topic
Author

Innner Class

Supree
Greenhorn

Joined: Feb 25, 2000
Posts: 27
Hi ,
Can inner class be abstract?
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
What happens when you compile the following?
<PRE>public class Test {
abstract class x{}
}</PRE>


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Supree
Greenhorn

Joined: Feb 25, 2000
Posts: 27
Thanks Tony.
Got you.
Innner class can be abstract
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
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

Joined: Nov 22, 2008
Posts: 18944
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?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Innner Class
 
Similar Threads
Doubt about diagram class (realization)
WA #1.....word association
can non-static inner class access any member
andrew has wii
Doubt about diagram class