Java Inheritance error: Implicit Super Constructor is undefined

前端 未结 2 555
情深已故
情深已故 2020-12-10 09:33

I am a novice to Java and just learning OOP concepts. Please review my code. I am getting the following error.- Implicit Super Constructor is undefined.

2条回答
  •  独厮守ぢ
    2020-12-10 09:51

    You are receiving this error because BoxSuper does not have a no-arg constructor. During your constructor call in BoxSub, if you do not define the super constructor call Java tries to automatically call the no-arg super() constructor.

    Either define a super constructor call in BoxSuper like so:

    class BoxSub extends BoxSuper
    {
        int weight;
        BoxSub(int a,int b,int c,int d)
        {
            super(a, b, c);
            weight=d;
        }
    }
    

    or define a no-arg constructor in BoxSuper:

    class BoxSuper
    {
        int height;
        int length;
        int width;
    
        BoxSuper(){}
    ...
    

提交回复
热议问题