Are there any reasons to have an abstract class with every method in the class defined?

后端 未结 7 623
名媛妹妹
名媛妹妹 2021-02-05 01:42

It seems that an abstract class means the definition of the class is not complete and hence cannot be instantiated.

And I saw some simple Java code which has an abstract

7条回答
  •  孤街浪徒
    2021-02-05 02:29

    You can have an abstract class that implements several interfaces. You need not implement these methods in an abstract class, but you do need to implement them in a subclass of your abstract class.

    E.g.

    public interface MyInterface{
        void hello();
    }
    
    public abstract class Clazzy implements MyInterface {
    //I need not have the interface method.
    }
    
    public class MySubclass extends Clazzy {
    
        @Override
        public void hello() {
            // I need to be here
        }
    
    }
    

提交回复
热议问题