Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Abstract Inner Classes 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 "Abstract Inner Classes" Watch "Abstract Inner Classes" New topic
Author

Abstract Inner Classes

krishna Mohan Athota
Greenhorn

Joined: Jul 18, 2009
Posts: 10
Hi,

When i wrote the class with an "abstract method" as :

-----------------------------------------------------
class base{
abstract void f();
}

Compilation ERROR:
base is not abstract and does not override abstract method f() in base

------------------------------------------------
class base{
abstract class AbstractClass { }
}

Compiled successfully
-----------------------------------------------------

An abstract "Inner Class" is also an abstarct element. So i beleive we should modify the class outer also with abstract modifier. why we are not geeting the compilation ERROR?

Could anyone clarify me?

Thank you
KM
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Only abstract class can contain abstract methods.
Base class in your example is not abstract, but has abstract method - and you got compiller error.
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 787

@ Krishna

You can give abstract modifier for outer class.
See the following



Only the thing is you cannot instantiate abstract class


SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
Anastasia Sirotenko
Ranch Hand

Joined: Jul 20, 2009
Posts: 64
krishna Mohan Athota wrote:
An abstract "Inner Class" is also an abstarct element. So i beleive we should modify the class outer also with abstract modifier. why we are not geeting the compilation ERROR?

Inner classes are not like methods, the are classes. When you declare abstract inner class, you can declare its subclasses in the same outer class, and implement different inner class realizations, and use all of them in your outer class as needed. You can even have abstract private inner class, since all it's subclasses can be implemented inside the same outer class.
Remember you cannot have abstract private methods, cause abstract methods are all due to overriding in some descendant classes.


[SCJP 6.0]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Abstract Inner Classes
 
Similar Threads
Constructor
is it valid to declare an inherited method as abstract?
K & B book--where is the 2nd edition errata?
java
Interface problem