• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Doubt regarding abstract class

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Sheriff
Posts: 28436
104
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 80960
525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
rajkiran vadla, welcome to the Ranch
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 80960
525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure Vat,
Your post was moved to a new topic.
 
You save more money with a clothesline than dozens of light bulb purchases. Tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic