This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
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

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
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: 63331

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] [Bear's FrontMan] [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.
Sunny Jain
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: 44433
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:
subject: abstract methods
It's not a secret anymore!