没有方法main?
public class Person
{
static int count =0;
protected String name;
protected int age;
public Person(String n1,int a1)
{
name=n1;
age=a1;
this.count++;
}
public String toString()
{
return this.name+","+this.age;
}
public void display()
{
System.out.print("本类名="+this.getClass().getName()+";");
System.out.println("父类名="+this.getClass().getSuperclass().getName());
System.out.print("Person.count="+this.count+" ");
System.out.print("Student.count="+Student.count+" ");
Object obj=this;
if(obj instanceof Student)
System.out.println(obj.toString()+"是Student类对象");
else if(obj instanceof Person)
System.out.println(obj.toString()+"是Person类对象");
}
}
class Student extends Person
{
static int count=0;
protected String dept;
protected Student (String n1,int a1,String d1)
{
super(n1,a1);
dept=d1;
this.count++;
}
public String toString()
{
return super.toString()+","+dept;
}
public void display()
{
super.display();
System.out.print("super.count="+super.count);
System.out.println(" ;this.count="+this.count);
}
public static void main(String args[])
{
Person per=new Person("王永涛",23);
per.display();
Student stu = new Student("张小三",22,"计算机系");
stu.display();
}
}
为什么会出现错误 exception in thread "main" java.lang.NoSuchMethodError:main
{
static int count =0;
protected String name;
protected int age;
public Person(String n1,int a1)
{
name=n1;
age=a1;
this.count++;
}
public String toString()
{
return this.name+","+this.age;
}
public void display()
{
System.out.print("本类名="+this.getClass().getName()+";");
System.out.println("父类名="+this.getClass().getSuperclass().getName());
System.out.print("Person.count="+this.count+" ");
System.out.print("Student.count="+Student.count+" ");
Object obj=this;
if(obj instanceof Student)
System.out.println(obj.toString()+"是Student类对象");
else if(obj instanceof Person)
System.out.println(obj.toString()+"是Person类对象");
}
}
class Student extends Person
{
static int count=0;
protected String dept;
protected Student (String n1,int a1,String d1)
{
super(n1,a1);
dept=d1;
this.count++;
}
public String toString()
{
return super.toString()+","+dept;
}
public void display()
{
super.display();
System.out.print("super.count="+super.count);
System.out.println(" ;this.count="+this.count);
}
public static void main(String args[])
{
Person per=new Person("王永涛",23);
per.display();
Student stu = new Student("张小三",22,"计算机系");
stu.display();
}
}
为什么会出现错误 exception in thread "main" java.lang.NoSuchMethodError:main
...全文
相关推荐
10个经典的Java main方法面试题
这意味着,如果没有main方法,Java程序将无法启动。在main方法中,通常会进行一些初始化操作,如创建对象、调用其他方法或控制程序流程。10. 变量args在main方法中的作用是什么?
如何解释 Python 中没有 main 函数的原因.docx
其中最引人注目的一点就是 Python 中没有显式定义 main 函数的概念。这与我们习惯的编程模式形成了鲜明的对比,那么,为什么 Python 会选择这样一种设计呢?
Maven 项目生成jar运行时提示“没有主清单属性”
什么是主清单属性?----------------在 Java 中,主清单属性(Main-Class)是指 Java 应用程序的入口类,也就是说,它是程序的启动点。
2023年java面试题(含答案).docx
不用 main 方法如何定义一个类?在 Java 中,main 方法是类的入口点,如果没有 main 方法,我们不能运行 Java 类。
详解eclipse将项目打包成jar文件的两种方法及问题解决方法
问题三:为什么我的main-class无法browse文件?解决方法:先用eclipse自带的export查看main-class名字(export方法如 上面),再复制粘贴填下去继续步骤。


Java SE
