• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt regarding abstract class  RSS feed

 
Jay Shukla
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have small doubt regarding Abstract class.

"If a class has single abstract method, than class must be declared as an abstract class."

But Does it necessary that abstract class must have a single abstract method? It abstact class does not have single abstract method then there is no meaning of creating that class as an abstract class. It is useless to create a class as an abstract without having any abstract method in it.


I tried to find answer to my above doubt but its not clearly mentioned in the book or site.

Could anyone please help me clarifying my above doubt?

Thanks in Advance.


 
Paul Clapham
Sheriff
Posts: 22834
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay Shukla wrote:"If a class has single abstract method, than class must be declared as an abstract class."

But Does it necessary that abstract class must have a single abstract method?

Your logic is perfect. No, that statement does not imply that an abstract class must have an abstract method. And in fact it is possible to create an abstract class which has no abstract methods. (Of course you could have tried that yourself.)
It abstact class does not have single abstract method then there is no meaning of creating that class as an abstract class. It is useless to create a class as an abstract without having any abstract method in it.

On the other hand there are competent programmers who have done exactly that. So your opinion differs from theirs.
 
rajkiran vadla
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Actually Abstract means it impose the class which is extending the abstract class to implement the abstract methods in it.So if you dont have any abstract methods in it there is a possibility to have abstract methods in it
in the future.

The base line is whenever you impose some class to have the body of the abstract methods then only we go for abstract class.


Thanks
Rajkiran
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rajkiran vadla, welcome to the Ranch
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jay Shukla wrote:It abstact class does not have single abstract method then there is no meaning of creating that class as an abstract class.

Ah, but you forgot one other very important point about an abstract class: it cannot be instantiated (ie, you cannot call 'new' on it); therefore, it you have a class that you don't want to be instantiated directly, you could make it abstract.

Winston
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure Vat,
Your post was moved to a new topic.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!