Can a java abstract class implement an interface?

example

Let’s take a look at the picture below:
Insert image description here
ps: You can find that an abstract class can implement the interface, and you will not be prompted to implement the interface at all. I think it's because the abstract class itself is abstract and cannot be instantiated. Even if the interface method is implemented here, it may still be overridden by a specific subclass, so there is no point in prompting.
But if you insist on implementing this interface, of course it is possible.

 */
public abstract class Abstrate implements Power12v {
    
    

    protected void doSomething(){
    
    
        System.out.println("AAA");
    }

    /**
     * 这个是接口的方法
     */
    public void outPut220v() {
    
    
        System.out.println("正在输出220v电流....");
    }
    
    public abstract void doSomething2();


}

think

The key point is to remember that abstract classes and interfaces are designed to abstract actual things. The difference is that what is abstracted from the interface are interface methods, regardless of implementation. Abstract classes extract both attributes and methods. There are abstract methods that need to be implemented by subclasses themselves, and there are already implemented methods for subclasses to inherit. Another thing to note is that abstract things cannot be instantiated!

Guess you like

Origin blog.csdn.net/mofsfely2/article/details/120889644