Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

implementing abstract method in one class in another abstract class

 
praveen kumar gowda
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Supose if have two class say class1 and class 2 both are abstract ...

if a method in class1 is abstact ,,can i implement this method in class2 since it is abstact...
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. is class1 and class2 has any relation?

2. so far what you have done?
 
Jim Pouwels
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can easily try this in your IDE (f.e. eclipse).

But, for now: Yes, this is possible. An abstract class can have both abstract AND implemented methods which are inherited from a super abstract class.

NOTE: You're not mentioning that class2 extends from class1. I'm assuming that that is what you're trying to do.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abstract classes can have non-abstract methods. For that matter you can have an abstract class with no abstract methods (though you would not want to do this). But a abstract method can only be present in an abstract class.
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Sanaulla wrote:For that matter you can have an abstract class with no abstract methods (though you would not want to do this).

You might want to do that. See HttpServlet, for example. Or java.awt.event.MouseAdapter. In both cases you need to override at least one of several methods to make it useful, but if they were marked abstract you'd have to implement all of them.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:
Mohamed Sanaulla wrote:For that matter you can have an abstract class with no abstract methods (though you would not want to do this).

You might want to do that. See HttpServlet, for example.


Ah ok, but I think this is confusing right?
but the documentation says:
Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A subclass of HttpServlet must override at least one method, usually one of these:

And may be that is why its declared Abstract.
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To me abstract just means "there's no reason to ever instantiate this, so stop anyone doing it, as it would be a mistake". It's a semantic issue. If you see something is abstract, you know it is only meant to be subclassed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic