File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "abstract VS inheritance" Watch "abstract VS inheritance" New topic
Author

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
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

What do you mean by "usual inheritance"?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

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

hth
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: abstract VS inheritance