首先先建立一个父类(动物类),定义的是姓名,
/
* 父类,动物类
* @author liuchunyong
*
*/
public abstract class Animal {
private String name;
public Animal() {
}
public Animal(String name){
this.name=name;
}
public String getName() {
return name;
}
/
再次定义一个接口,定义腿的数量,接口的作用为规范你使用这个接口那就必须存在他定义的方法
/
//下面就是定义猫,狗,继承父类并且继承接口,海豚没腿所以只是继承父类
}
//狗
}
//海豚类
}
/
下面我们在定义一个类,存放我们的数字,并且定义显示动物方法,修改方法
/
import java.util.*;
public class AnimalMgr {
Scanner input=new Scanner(System.in);
Animal[] an=new Animal[3];
//初始化数据
int choose;//定义是否输入为零,退出
public void init(){//动物信息
//展示所有动物的信息
}
System.out.println(“是否要继续操作:按0进行修改操作,其它任意数字退出”);
choose=input.nextInt();
String[] names=new String[3];
int[] nums=new int[2];
System.out.println(“请输入猫的名字:”);
names[0]=input.next();
System.out.println(“请输入猫的腿数:”);
nums[0]=input.nextInt();
if(nums[0]!=4){
throw new Exception(“猫只有四条腿”);
}
System.out.println(“请输入狗的名字:”);
names[1]=input.next();
System.out.println(“请输入狗的腿数:”);
nums[1]=input.nextInt();
if(nums[1]!=4){
throw new Exception(“狗只有四条腿”);
}
}
//最后建立一个测试的类,来显示给用户
import java.util.Scanner;
public class Test {
}
有参考博客: https://blog.csdn.net/ruiguang21/article/details/
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.bianchenghao6.com/h6javajc/5832.html