Java – why must an abstract method be implemented by the first concrete class rather than a further chain?
•
Java
I'm curious why abstract methods must be overridden by the first concrete implementation class rather than hierarchy changes
I'm not suggesting that I want to do this, but I'm curious why it must be first-class
Consider this example
abstract class Upper { abstract void doSomething(); } class Middle extends Upper { void doSomething() { // I'm forced to be implemented here } } abstract class Lower extends Middle { } class Bottom extends Lower { void doSomething() { // I'm valid,but I'm too far down the hierarchy } }
Solution
By definition, a normal class must implement all abstract methods If you want to declare abstraction, you don't have to implement this method in middle
An ordinary class can be instantiated, but an abstract class cannot Think about what happens if you try to call a method that is not implemented in a class
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码