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 implementing abstract method in one class in another abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "implementing abstract method in one class in another abstract class" Watch "implementing abstract method in one class in another abstract class" New topic
Author

implementing abstract method in one class in another abstract class

praveen kumar gowda
Greenhorn

Joined: Feb 20, 2012
Posts: 23
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

Joined: Jan 28, 2008
Posts: 5575

1. is class1 and class2 has any relation?

2. so far what you have done?
Jim Pouwels
Ranch Hand

Joined: Feb 22, 2012
Posts: 61
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

Joined: Sep 08, 2007
Posts: 3064
    
  33

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.

Mohamed Sanaulla | My Blog
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

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

Joined: Sep 08, 2007
Posts: 3064
    
  33

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

Joined: Apr 06, 2010
Posts: 4343
    
    8

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.
 
Consider Paul's rocket mass heater.
 
subject: implementing abstract method in one class in another abstract class
 
Similar Threads
error message
Dan Chisholm question about abstract classes
Abstract Class & Interface
Inner classes
HttpServlet