Вывод информации из "третьего" класса

public class Main {
    public static void main(String[] args) {
        Leg leg = new Leg(1, 2, 3);
        Table table = new Table("wood", leg);

        table.displayTableInfo();
    }
} 

public class Table {
    public String material;
    public Leg leg;
    
    // constructor
    public Table(String material, Leg leg) {
        this.material = material;
        this.leg = leg;
    }
    
    // method
    public void displayTableInfo() {
        System.out.println(this.material + this.leg);
    }
}

public class Leg {
    public int height;
    public int width;
    public int length;
        
    // constructor
    public Leg(int height, int width, int length) {
        this.height = height;
        this.width = width;
        this.length = length;
    }
        
    // method
    public void displayLegInfo() {
        System.out.println(this.height + this.width + this.length);
    }
}

Когда вызываю table.displayTableInfo() программа пишет, что значения Leg равны null. Как правильно передать информацию, чтобы при вызове table.displayTableInfo() выводилась и информация о Leg?


Ответы (0 шт):