aspose file tools*
The moose likes Java in General and the fly likes Why do we have concrete methods in abstract class ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Why do we have concrete methods in abstract class ?" Watch "Why do we have concrete methods in abstract class ?" New topic
Author

Why do we have concrete methods in abstract class ?

Dhaval Shah
Ranch Hand

Joined: Jun 10, 2005
Posts: 56
Can anyone please tell me the logic behind having concrete methods in abstract class as we cant instantiate them ?

E.g. - (Abstract Class)InputStream - has concrete method - read (byte [] b)
and the subclass FileInputStream also has method -- read (byte [] b)

Now we cant create an object of InputStream as it is an abstract class then why do we have concrete method (read (byte [] b))in InputStream ? What is the use of having concrete methods in abstract class

Thanks
Dhaval


Thanks and Regards,<br />Dhaval Shah<br />SCJP 1.4<br />SCWCD 1.4
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12783
    
    5
having concrete methods in abstract class

It is a design decision by the programmer to enforce a particular vision of how the class is to be used. In InputStream it ensures that extending classes do not need to provide an implementation of read( byte[] ) in order to work.

You can in fact have a class declared abstract but containing all concrete methods.

Bill
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Q: Why have abstract classes at all, since they can't be instantiated?
A: They can be subclassed!

Q: Why have concrete methods in abstract class, since they can't be instantiated?
A: They can be subclassed! The subclasses can inherit these methods.


There is no emoticon for what I am feeling!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why do we have concrete methods in abstract class ?