JAVA小程序没错,但不能编译的问题?(在线等)

来源:百度知道 编辑:UC知道 时间:2024/06/08 00:42:05
刚学JAVA 跟据教程写出了下面这个,在Eclipse中显示没有错,但不能编译.
忘高手帮个忙.
留个QQ.谢谢了.....

class Animal
{
int height,weight;

void eat()
{
System.out.println("animal eat");
}

void sleep()
{
System.out.println("animal sleep");
}
}

class fish extends Animal
{
}

class Integration
{
public static void main(String[] args)
{
Animal An=new Animal();
fish fi=new fish();

An.eat();
fi.eat();

}

}

文件名为
Integration.java

class Animal
{
int height,weight;

void eat()
{
System.out.println("animal eat");
}

void sleep()
{
System.out.println("animal sleep");
}
}

class fish extends Animal
{
}

public class Integration
{
public static void main(String[] args)
{
Animal An=new Animal();
fish fi=new fish();

An.eat();
fi.eat();

}

}

拜托,java最常识:主函数所在类必须和代码的命名一致,还有一个文件中必须只能有一个主类,看书认真点嘛。
还有,怎么现在的教材入门都是拿Eclipse做demo了吗?基础不牢怎么往下学啊?

程序没有错,注意类文件名与Main方法类名一致。。
初学不要用大型集成开发环境。EditPlus或记事本即可。。

class Integration 应该是public class Integration()

在JAVA中只有一个主类,并用public 表明,你的代码里没有声明。

除了主类有问题,还有一个可能是你的eclipse没有在项目中选定自动构建。