Why do I need to write a constructor here explicitly?

前端 未结 7 1888
無奈伤痛
無奈伤痛 2021-01-15 11:28

This is how I encountered the problem. I am giving an example:

package check;

public class Check {
  int a,b;
  Check (int i,int j) {
    a = i;
    b = j;
         


        
7条回答
  •  太阳男子
    2021-01-15 11:53

    Because when creating an object in Java, the classes superconstructor will have to be called first. Since you don't have default values for the superconstructor and you don't have a default constructor for the superclass, you need to provide one for the subclass, which calls super(i, j)

提交回复
热议问题