• 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

Abstract Inner Classes

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic