多级继承-类从再次继承属性的类继承属性。
class Shape { public void display() { System.out.println("Inside display"); }} class Rectangle extends Shape { public void area() { System.out.println("Inside area"); } } class Cube extends Rectangle { public void volume() { System.out.println("Inside volume"); } } public class Tester { public static void main(String[] arguments) { Cube cube = new Cube(); cube.display(); cube.area(); cube.volume(); } }
输出结果
Inside display Inside area Inside volume