wood burning stoves
The moose likes Beginning Java and the fly likes abstract methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "abstract methods" Watch "abstract methods" New topic

abstract methods

jujahar singh

Joined: Jan 07, 2008
Posts: 4
The question is when we declare a method as abstract in a class we have to implement its body in the very first concrete class below it(in the inheritance tree). Why is the necessity to do this so that the lower subclasses can access those methods. In any case the lower subclasses will be extending to the class where the abstract methods are defined. Is there any specific reason for this or it is due to the thing that java is designed like this?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63862

Please take the time to choose the correct forum for your posts. This forum is for questions on HTML and JavaScript.

This post has been moved to a more appropriate forum.

[Asking smart questions] [About Bear] [Books by Bear]
jujahar singh

Joined: Jan 07, 2008
Posts: 4
sorry Bear Bibeault! I have just started learning java and i am new user to this forum that's why i mistakenly posted it at a wrong place.
Deepak Chopra
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

Hi as Per my point of view :

1) your point is also right, subclasses will have access to those methods.

2) If we don't want anyone to create instance of a class, mark that class as an abstract class.

Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46368
What you mean is that an object must implement every method it has. If you try calling an abstract method on an object it would cause all sorts of errors. So abstract methods have to be implemented on any objects of that class (or its subclasses).
jujahar singh

Joined: Jan 07, 2008
Posts: 4
Thanks Campbell and Sunny! I got it.
I agree. Here's the link: http://aspose.com/file-tools
subject: abstract methods
It's not a secret anymore!