集册 Java实例教程 类创建测验

类创建测验

欢马劈雪     最近更新时间:2020-01-02 10:19:05

532
创建一个具有实例变量的类,该实例变量用于高度,重量和深度。
/**from nowjava.com - 时  代  Java**/

class Sample {

    int height;

    int weight;

    int depth;

}


public class Main {

    public static void main(String[] arguments) {

        Sample thing = new Sample();

        thing.height = 72;

        thing.weight = 1;

        thing.depth = 42;

        System.out.println("Height: " + thing.height);

        System.out.println("Weight: " + thing.weight);

        System.out.println("Depth: " + thing.depth);

    }

}