Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

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.

 
Everybody's invited. Even this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic