user2426316
user2426316

Reputation: 7331

How can I create a subclass of an abstract class automatically in Eclipse in Java?

say I had an abstract java class in eclipse. Now I want to create some subclasses of that abstract class. Is there a way to create them automatically where I just enter the name of the class and eclipse creates the necessary methods?

I thought that I would find it in the "Refactor" option but I didn't. Can someone help me?

Upvotes: 1

Views: 11972

Answers (3)

Florent Bayle
Florent Bayle

Reputation: 11890

Yes, create a new class using Right Click (on the package where you want to create the class) > New > Class, and in the SuperClass field, you can select your abstract class. Be sure that the checkbox Which method stubs would you like to > Inherited abstract methods is checked.

Create a subclass of an abstract class

If you have already created your class, you can make it extend you abstract class by hand, and use Right Click (on the source code) > Source > Override/Implement Methods... and choose which methods you want to implement (if they are not already implemented).

Override/Implment Methods...

An other way to do it, is to extend your abstract class by hand, and use the Quick Fix provided by Eclipse to Add unimplemented methods. You can call the Quick Fix tooltip by highlighting the error and using Ctrl+1, or by clicking on the error icon on the left of the code.

Quick Fix

Upvotes: 5

gerrytan
gerrytan

Reputation: 41123

Just create a class extending the abstract class, by default eclipse will add all unimplemented methods

Upvotes: 0

John B
John B

Reputation: 32949

Use the New Class as normal but then specify your abstract class as the Superclass. Then check Which methods stubs would you like to create -> inherited abstract methods

Upvotes: 0

Related Questions