package bzu.aa;
public class Vehicle {
protected int capacity;
public Vehicle (){
capacity=2;
System.out.println("执行交通工具类的无参构造方法.");
}
public Vehicle(int capacity){
//super();
this.capacity=capacity;
System.out.println("执行交通工具类的有参构造方法.");
}
public int getCapacity(){
return capacity;
}
public void setCapacity(int capacity){
this.capacity=capacity;
}
public void print(){
System.out.println("交通工具的载客量为:"+capacity);
}
}
Car类:
package bzu.aa;
public class Car extends Vehicle {
protected int speed;
public Car(){
super();
speed=0;
System.out.println("执行汽车类的无参构造方法.");
}
public Car(int speed){
super(6);
this.speed=speed;
System.out.println("执行汽车类的有参构造方法.");
}
public int speedUp(int speed){
this.speed=speed+10;
return speed;
}
public int speedDown(int speed){
this.speed=speed-10;
return speed;
}
public void print(){
System.out.println("汽车的载客量为:"+capacity+";汽车的速度为:"+speed);
}
}
Bus类:
package bzu.bb;
import bzu.aa.Car;
public final class Bus extends Car{
public int capacity;
public Bus(){
super();
capacity=20;
System.out.println("执行公交车类的无参构造方法.");
}
public Bus(int capacity){
super(40);
this.capacity=capacity;
System.out.println("执行公交车类的有参构造方法.");
}
public void print(){
System.out.println("公交车的的载客量为:"+capacity+";公交车的速度为:"+speed+";汽车类的载客量为:"+getCapacity());
}
}
Test类:
package bzu.bb;
import bzu.aa.Car;
public class Test {
public static void main(String[] args) {
Car car=new Car();
car.speedUp(40);
car.print();
car.speedDown(30);
car.print();
Bus bus=new Bus(20);
bus.print();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有