• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

abstract method  RSS feed

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


Have a look ...



 
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
Boost this thread!