训练 1 储蓄卡和信用卡
创建银行卡类,并设计他的两个字类:储蓄卡类与信用卡类。
public class bankcard {
public static void main(String[] args) {
}
}
class cuncard extends bankcard{//储蓄卡
}
class xincard extends bankcard{//信用卡
}
训练 2 水果售价
使用继承展示经过人工包装的水果与普通水果在价格上的区别。
public class fruit {
public static void main(String[] args) {
System.out.print("普通水果:");
System.out.println("很便宜");
peoplefruit a = new peoplefruit();//创建对象
a.frout1();//调用方法
}
}
class peoplefruit extends fruit {//创建经过人工包装的水果
public void frout1() {//成员方法
System.out.print("人工包装的水果:");
System.out.println("很贵");
}
}