看看这些代码:好像没出错,但编译出现这个问题?文件名为Student.java
//继承的运用
package 飞飞小程序;
public class Student {
int stu_id;
void set_id(int id){
stu_id=id;
}
void show_id(){
System.out.println("The student's ID is "+stu_id);
}
}
class UniversityStudent extends Student{
int dep_number;
void set_dep(int dep_num){
dep_number=dep_num;
}
void show_dep(){
System.out.println("The dep_number is:"+dep_number);
}
}
class StudentShow{
public static void main(String[] args){
UniversityStudent zhu=new UniversityStudent();
zhu.set_dep(0500510202);
zhu.set_id(4666189);
zhu.show_id();
zhu.show_dep();
}
}
调试出现:
java.lang.NoSuchMethodError: main
Exception in thread "main"
----------------解决方案--------------------------------------------------------
知道哪出错了,原来是文件名出错,须为:StudentShow.java!但不知道为什么要这样做?
----------------解决方案--------------------------------------------------------
奇怪,什么为什么要这样做?这不是test继承吗?
----------------解决方案--------------------------------------------------------
一个类里面只能有一个PUBLIC类,而且这个main方法要写到这个PUBLIC类中。
你这样写是找不到main方法的,如果你用ECLIPSE来做的话,选RUN AS 里面根本不会出现可用的类。
----------------解决方案--------------------------------------------------------
你MAIN函数在哪个类里,就用哪个名字
因为MAIN函数是入口,虚拟机不知道你的MAIN在哪里
而虚拟机会在与文件名字相同的
类里面找MAIN函数当入口。
初学,不知道对不对
----------------解决方案--------------------------------------------------------
public class
这个类可以访问
public static main
这个函数可以访问
这样你就能在什么也没有创建的时候
运行主函数了
----------------解决方案--------------------------------------------------------
每一个方法只有一个公共类,而且必须是启动类、
----------------解决方案--------------------------------------------------------