• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract Inner Classes

 
krishna Mohan Athota
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 802
Hibernate Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Krishna

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



Only the thing is you cannot instantiate abstract class
 
Anastasia Sirotenko
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic