明天要考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());
}
}
感慨啊。。。