其他分享
首页 > 其他分享> > 20220721第八组张立

20220721第八组张立

作者:互联网

知识点

/**

示例

点击查看代码
public class Bike {
 
	public int wheels = 2; //轮子数量
	
	public void run(){
		System.out.println("自行车都能跑");
	}
}
点击查看代码
public class RaceBike extends Bike {
 
	public int gear = 2; // 齿轮个数
 
	public void speedUp() {
		System.out.println("变速自行车可以加速");
	}
 
	public void speedDown() {
		System.out.println("变速自行车可以减速");
	}
}
- *测试类*

<details>
<summary>点击查看代码</summary>

public class Test {

public static void main(String[] args) {
	RaceBike bike = new RaceBike();
	int wheels = bike.wheels; //获取父类的成员变量wheels
	int gears = bike.gear;
	System.out.println("变速车的轮子数量是:" + wheels);
	System.out.println("变速车的齿轮数是:" +  gears);
	bike.run(); //调用父类的跑的方法
	bike.speedUp();
	bike.speedDown();
}

}

</details>
**学习情况:** 了解
**学习心情** 还行

标签:super,组张立,第八,20220721,方法,子类,父类,重写,public
来源: https://www.cnblogs.com/damecss/p/16503019.html