• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract method

 
itisha jain
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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
 
Lalitha Gottumukkula
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope an example makes the point clearer.....
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,


Have a look ...



 
Akshay Kiran
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • 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
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic