java--继承(1)

public class Car {
	//车类
	private String plate;	//车牌
	private String type;	//车型
	public void Start(){
		System.out.println("我是车,我启动");
	}
	public void Stop(){
		System.out.println("我是车,我停止");
	}
	public String getPlate() {
		return plate;
	}
	public void setPlate(String plate) {
		this.plate = plate;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	
}

//继承车类
public class Fcar extends Car{
	//家庭轿车类
	private String name;
	public Fcar(String name){
		this.name=name;
	}
	public void Start(){
		System.out.println("我是"+name+",我的汽车我做主");
	}
	public void Stop(){
		System.out.println("目的地到了,我们去玩吧");
	}
}

//继承车类
public class Taxi extends Car{
	//出租车类
	private String company;	//所属公司
	public Taxi(String company){
		this.company=company;
	}
	
	public void start() {
		System.out.println("乘客您好!\n我是"+this.company+"的,我的车牌号是"+this.getPlate()+",你要去那里?");
	}
	public void stop() {
		System.out.println("目的地已经到了,请您下车付款,欢迎再次乘坐!");
	}
	
}

public class Test {
	//测试类
	public static void main(String[] args) {
	Car c=new Car();
	c.Start();
	c.Stop();
	System.out.println("===========================");
	Fcar fc = new Fcar("张三丰");
	fc.Start();
	fc.Stop();
	System.out.println("============================");
	Taxi tc = new Taxi("景顺出租公司");
	tc.setPlate("京A0000");
	tc.start();
	tc.stop();
	}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值