为什么the section cannt be launched


package recta;
public class rect1 {

   protected int row;

   protected int col;
   int a[][] = new int[row][col];

   public rect1(int row, int col) {
       this.row = row;
       this.col = col;
   }

   void show() {
       int i, j;
       for (i = 0; i < row; i++) {
           for (j = 0; j < col; j++)
               System.out.print(a[i][j]);
           System.out.println(" ");
       }
   }

   void construct() {
       int i, j;
       for (i = 0; i < row; i++)
           for (j = 0; j < col; j++)
               a[i][j] = (int) Math.random();
   }

   void addtogether() {
       int i, j;
       int sum = 0;
       for (i = 0; i < row; i++)
           for (j = 0; j < col; j++)
               sum = sum + a[i][j];
       System.out.println("所有元素和为:" + sum);

   }
}

class square extends rect1{
   public  square (int row,int col)
   { 
       super(row,col);
   }
   
   public void addline()
   {int i;
    int sum=0;
       for(i=0;i<row;i++)
           sum=a[i][i]+sum;
       System.out.println("主对角线的元素和为:"+sum);
   }
   
   public static void main(String args[])
   {
       square s=new square(6,6);
       s.construct();
       s.addline();
   }
}
   

为什么the section cannt be launched

二维数组 a 初始化 要放到构造方法里

    int a[][];

    public rect1(int row, int col) {
        this.row = row;
        this.col = col;
        a = new int[row][col];
    }

哥们儿,二维数组初始化代码错了,逻辑就不对!以评论,莫辜负,希望你能够采纳
——————————————————————————————

public class rect1 {

   protected int row;

   protected int col;
   int a[][];

   public rect1(int row, int col) {
       this.row = row;
       this.col = col;
       a = new int[row][col]; // initialize the array here
   }

   // rest of the class code...
}