• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract VS inheritance

 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.


Then what is the advantage of using abstract vs usual inheritance?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64721
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "usual inheritance"?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like sofas, family photo albums, and so on. I, OTOH, got a peace pipe from the 1800s, a Revolutionary War musket, and a bunch of coins from the 1892 Columbian Exposition.
 
abalfazl hossein
Ranch Hand
Posts: 635
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear david

We have a class , and other class can inherited from that.

We have an abstract class. and other class can inherited from that.

The only difference is that we can not create an object of an abstract class.

Now, What is the advantage?If it is about inheritance, Then we can use inheritance as it .When to use abstract?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abstract class like an interface it provides specification and additionaly it can contain default implementation for a particular method . normally, it can be type for an implementors(classes which extends abstract class) .

*AbstractInterface* is a perfect example for your query . example : AbstractList,AbstractMap ... etc

hth
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abalfazl hossein wrote:When to use abstract?


When you are defining a class whose only purpose is to be extended, make it abstract.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic