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 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
Author

abstract methods

jujahar singh
Greenhorn

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
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

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
Greenhorn

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
Sheriff

Joined: Oct 13, 2005
Posts: 38491
    
  23
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
Greenhorn

Joined: Jan 07, 2008
Posts: 4
Thanks Campbell and Sunny! I got it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: abstract methods