How would one go about defining a method in a super class but leave the implementation to the sub classes?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Leave the method
abstract:Note that…
Abstract classes can’t be constructed (so
new A()would be an error, butnew B()would be fine), and subclasses need to implement all abstract methods unless they’re also abstract.With an abstract class, you can mix abstract and normal methods:
If all of the methods are abstract, it may make more sense to use an
interface, since classes an implement multiple interfaces:Note: Methods in an interface are automatically
abstractandpublic, unlike methods in classes, which are by default package private and not abstract.