Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract methods

 
jujahar singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64606
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jujahar singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Posts: 48363
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell and Sunny! I got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic