明天要考java,有幾個知識點不理解,求大佬可以把以下的題目代碼發壹下,能做幾個都好,只要註釋全就行~
還是耐著性子給妳做完了望采納。。。
第七題/** *?動物抽象類 */public?abstract?class?Animal?{
//顏色
private?String?color;
//類別
private?String?type;
//吃飯
public?abstract?void?eat();
//叫
public?abstract?void?cry();
//get?set方法省略。。。
}
/**
*?遊泳的接口 */public?interface?Swimable?{
//遊泳
public?void?swim();
}
/**
*?兔子類 */public?class?Rabbit?extends?Animal?{
@Override
public?void?eat()?{
System.out.println("小兔幾吃蘿蔔。。。");
}
@Override
public?void?cry()?{
System.out.println("小兔幾呵呵噠。。。");
}
}
/**
* 青蛙類 */public?class?Frog?extends?Animal?implements?Swimable?{
public?void?swim()?{
System.out.println("青蛙會蛙泳。。。");
}
@Override
public?void?eat()?{
System.out.println("青蛙吃昆蟲。。。");
}
@Override
public?void?cry()?{
System.out.println("青蛙呱呱叫。。。");
}
}
public?class?Test?{
public?static?void?main(String[]?args)?{
//兔子
Rabbit?rabbit?=?new?Rabbit();
rabbit.eat();
rabbit.cry();
//青蛙
Frog?frog?=?new?Frog();
frog.eat();
frog.cry();
frog.swim();
}
}第八題/**
*?學生類 */public?class?Student?{
//學號
private?String?id;
//姓名
private?String?name;
//性別
private?char?gender;
//年齡
private?int?age;
public?Student(String?id,?String?name,?char?gender,?int?age)?{
this.id?=?id;
this.name?=?name;
this.gender?=?gender;
this.age?=?age;
}
//獲得學號、姓名、性別、年齡
public?String?toString()?{
return?"學號:"+id?+"?姓名:"?+?name?+?"性別:"?+?gender?+?"?年齡:"?+?age;
}
//修改年齡
public?void?changeAge(int?range)?{
age?=?range;
}
//get?set方法省略。。。
}
public?class?Test?{
public?static?void?main(String[]?args)?{
Student?s?=?new?Student("alibb008",?"傑克馬",?'公',?18)?;
System.out.println(s.toString());
s.changeAge(50);
System.out.println(s.toString());
}
}
感慨啊。。。