• 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 method

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"A subclass of a class with an abtract method must provide n implementation for the abstract method".

The statement is given as false in khalid mughal.the explanation being...

Abstract methods foma superclass need not be implemented by a subclass.The subclass must then b declared abstract.

however,i thought the statement is true.Plz explain
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hope an example makes the point clearer.....
 
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,


Have a look ...



 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This should make it clearer

abstract class Abstract{
// A class with an abstract method
abstract void doThis();

}

abstract class A extends Abstract{
// extends abstract but provides no implementation, and hence decld. abstract

}

class B extends Abstract{
// B extends Abstract, but provides no implementation AND is NOT abstract
// The compiler throws an error

}

Therefore, a subclass of a class with an abstract method must either be declared abstract or must provide an implementation of the abstract method.
I put that phrase in bold because, it is only true for classes that have abstract methods, and not necessarily abstract classes in general.

abstract class A{
void someMethod(){}
}

class B extends A{
// not abstract, doesn't override the someMethod of A
// no problem
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic