public class Animal
{
Animal(){
}
public void eat()
{}
}
public class roushi extends Animal{
public roushi()
{
}
public void eat()
{
System.out.println ("食肉");
}
}
public class caoshi extends Animal{
public caoshi(){
}
public void eat()
{
System.out.println ("饲草");
}
}
public class test11 {
public static void main (String[] args)
{
caoshi cao = new caoshi();
cao.eat();
roushi rou=new roushi();
rou.eat();
}
}
报错 请指教
test11.java:1: 类 Animal 是公共的,应在名为 Animal.java 的文件中声明
public class Animal
^
test11.java:10: 类 roushi 是公共的,应在名为 roushi.java 的文件中声明
public class roushi extends Animal{
^
test11.java:21: 类 caoshi 是公共的,应在名为 caoshi.java 的文件中声明
public class caoshi extends Animal{
------解决方案--------------------
去掉前三个类声明的限定符 public