一道 三个类依次继承下来的问题?(求指导)
下面是一道关于继承的题目,我总是没发理解,不知道怎么做,有能帮忙解释一下的吗?要求,每个类单独保存为一个文件,文件名要和类名相同;其中,Transportation类为Bicycle类的超类,Bicycle类为MultispeedBicycle类的超类。在相应的缺省构造方法中将属性owner初始化为你的姓名,number初始化为你的学号,size初始化为你的机器号,level初始化为10 。编译通过后可编译运行文件MultispeedBicycleTest.java测试。
/*程序入口*/
public class MultispeedBicycleTest {
public static void main(String[] args) {
System.out.println("-------缺省构造方法测试-------");
MultispeedBicycle m1 = new MultispeedBicycle();
m1.show();
/* System.out.println("-------get、set方法测试-------");
m1.setOwner("黄老邪");
m1.setNumber("8888");
m1.setSize(88);
m1.setLevel(8);
System.out.println("拥有者:" + m1.getOwner());
System.out.println("编号:" + m1.getNumber());
System.out.println("大小:" + m1.getSize());
System.out.println("级别:" + m1.getLevel());
System.out.println("-------带参数构造方法测试-----------");
MultispeedBicycle m2 = new MultispeedBicycle("老顽童","7777",77,7);
m2.show();
*/
}
}
第一个类
public class Transportation {
private String owner;
private String number;
public Transportation()
{this.owner="11";
this.number="25";}
public Transportation(String owner, String number)
{this.owner=owner;
this.number=number;}
public String getOwner()
{return this.owner;}
public void setOwner(String owner)
{ this.owner=owner;}
public String getNumber()
{return this.number;}
public void setNumber(String number)
{this.number=number;}
public void show()
{System.out.println("姓名:"+owner);}
}
继承了第一个类的第二个类
public class Bicycle extends Transportation {
private int size;
public Bicycle()
{}
public Bicycle(String owner,String number,int size)
{ this.owner=owner;
this.number=number;
this.size=size;
}
public int getSize(int size)
{return this.size;}
public void show()
{}
}
继承了第二个类的第三个类
public class MultispeedBicycle extends Bicycle {
private int level;
public MultispeedBicycle() {
}
public MultispeedBicycle(int level)
{
this.level=level;}
public int getLevel()
{return level;}
public void setLevel(int level)
{this.level=level;}
public void show()
{}
}