It's not a secret anymore!
The moose likes Beginning Java and the fly likes abstract VS inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "abstract VS inheritance" Watch "abstract VS inheritance" New topic

abstract VS inheritance

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
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

Joined: Jan 10, 2002
Posts: 63540

What do you mean by "usual inheritance"?

[Asking smart questions] [About Bear] [Books by Bear]
David Newton

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Sep 06, 2007
Posts: 635
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

Joined: Jan 28, 2008
Posts: 5575

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

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

abalfazl hossein wrote:When to use abstract?

When you are defining a class whose only purpose is to be extended, make it abstract.

[Jess in Action][AskingGoodQuestions]
subject: abstract VS inheritance
It's not a secret anymore!