Can I implement abstract methods in an abstract base class A in java?
If the answer is yes and there is an implemented abstract method in a base class A and there is a derived class B from A (B is not abstract). Does B still has to implement that base abstract method?
If I understand your question correctly, Yes.
public abstract class TopClass {
public abstract void methodA();
public abstract void methodB();
}
public abstract class ClassA extends TopClass {
@Override
public void methodA() {
// Implementation
}
}
public class ClassB extends ClassA {
@Override
public void methodB() {
// Implementation
}
}
In this example, ClassB will compile. It will use it's own implementation of methodB(), and ClassA's implementation of methodA(). You could also override methodA() in ClassB if desired.
You could have two abstract classes, X and Y, where Y extends X. In that case it could make sense for Y to implement an abstract method of X, while still being abstract. Another non-abstract class Z could extend Y. However, in your example, for A to implement its own abstract methods is a contradiction, the point of making them abstract is so it doesn't provide implementations, it just specifies what the method signatures should look like.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With