Why should I call super() in Java?

后端 未结 5 1131
青春惊慌失措
青春惊慌失措 2021-01-22 04:17

I see an example from a book that I read about java:

public class A{
  public A(){
      System.out.println(\"A\");
   }
}

public class B extends A{
    public          


        
5条回答
  •  隐瞒了意图╮
    2021-01-22 04:59

    Java implicitly calls the no argument super constructor. But it may happen that the super class constructor has arguments or there are multiple super class constructors. In this case you would have to explicitly mention which super class constructor you want to call (the compiler leaves that up to you)

提交回复
热议问题