wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes extending abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "extending abstract class" Watch "extending abstract class" New topic
Author

extending abstract class

Paul Salerno
Ranch Hand

Joined: Jan 17, 2002
Posts: 172
A newbie question:
abstract class Shape
{
abstract void draw();
}
abstract class TwoDShape extends Shape
{
}
I want to be sure that TwoDShape doesnt have to override abstract method of superclass. However, if TwoDShape were not declared abstract then it must provide implementation otherwise a compiler error will ensue. I hope I'm correct on this, just need confirmation. TIA
Stefan Zoerner
Author
Ranch Hand

Joined: Nov 29, 2001
Posts: 121
Hello Paul!
You are correct. There are (at least) two options in your case:
a) declare the subclass abstract.
Then you do not have to implement the abstract method in the base classs
b) implement the method in the subclass

Then then class can be concrete (w.o. "abstract"), that is you can make instances of it via "new".
Hope that helps.
Greetings from Hamburg,
Stefan


Stefan Zoerner
Author of German LDAP-Book
Committer at Apache Directory Project
Paul Salerno
Ranch Hand

Joined: Jan 17, 2002
Posts: 172
Stephen your way too quick for me, I appreciate that. So you are able to implement the draw() with just {} and nothing in the body?
Stefan Zoerner
Author
Ranch Hand

Joined: Nov 29, 2001
Posts: 121
Hello Paul!
Implementing a method is just to add a body to the signature given in the interface or the abstract class.
In the most simple case, the body is empty and the method does nothing. The compiler will not complain, but in a realistic scenario, you would add some statements in between the { ... } to have some behaviour
I'm not sure, whether this is the answer to your question
Greetings, Stefan
Paul Salerno
Ranch Hand

Joined: Jan 17, 2002
Posts: 172
absolutely Stephan, I've seen this done before when implementing some interface but not using those methods. Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: extending abstract class