继承的JAVA实现-面向对象的概念和Java实现-2

继承的JAVA实现演示:示例1编写一个父类使用extends关键字,编写子类class Car extends Vehicles { /**构造方法. */ Car() { } /**显示子类Car的信息. */ void show() { System.out.println(“从子类Car中输出的信息"); System.out.println(“交通工具的名称- " + name); System.out.println(“交通工具的颜色- " + color); System.out.println(“座位的数量- " + seats); System.out.println(""); } } class Vehicles { /**存储交通工具的名称. */ protected String name = "Honda Civic"; /**存储颜色信息.*/ protected String color = "Red"; /**存储座位信息. */ protected int seats = 5; /**构造方法.*/ Vehicles() { } /** *显示父类的详细信息*/ void showDetail() { System.out.println("从父类Vehicles中输出的信息"); System.out.println("名称- " + name); System.out.println("颜色- " + color ); } } public class CarTest { /** *构造方法*/ CarTest() { } /** *这是main方法* @param args传递至main方法的参数*/ public static void main(String[] args) { /*声明一个对象*/ Car vehicle = new Car(); vehicle.showDetail(); } }
ppt 文件大小:1007.5KB