java 在类 中找不到主方法, 请将主方法定义为: public static void main(System.args[]) 是怎么回事?
publicclassTeacher{privateStringname;privateintid;privateintage;publicStringgetName()...
public class Teacher{
private String name;
private int id;
private int age;
public String getName(){
return name;}
public int getId(){
return id;}
public int getAge(){
return age;}
public void setName(String teaName){
name=teaName;}
public void setId(int teaId){
id=teaId;}
public void setAge(int teaAge){
age=teaAge;}
public Teacher(String nname,int iid,int aage){
name=nname;id=iid;age=aage;}
Teacher(){
name="张三";
id=456;
age=18;}
}
class TeacherTest{
public static void main(String args[]){
Teacher s1=new Teacher("李四",123,20);
Teacher s2=new Teacher();
System.out.println("姓名:"+s1.getName()+"学号:"+s1.getId()+"年龄:"+s1.getAge());
System.out.println("姓名:"+s2.getName()+"学号:"+s2.getId()+"年龄:"+s2.getAge());
}
} 展开
private String name;
private int id;
private int age;
public String getName(){
return name;}
public int getId(){
return id;}
public int getAge(){
return age;}
public void setName(String teaName){
name=teaName;}
public void setId(int teaId){
id=teaId;}
public void setAge(int teaAge){
age=teaAge;}
public Teacher(String nname,int iid,int aage){
name=nname;id=iid;age=aage;}
Teacher(){
name="张三";
id=456;
age=18;}
}
class TeacherTest{
public static void main(String args[]){
Teacher s1=new Teacher("李四",123,20);
Teacher s2=new Teacher();
System.out.println("姓名:"+s1.getName()+"学号:"+s1.getId()+"年龄:"+s1.getAge());
System.out.println("姓名:"+s2.getName()+"学号:"+s2.getId()+"年龄:"+s2.getAge());
}
} 展开
11个回答
推荐于2018-02-11 · 知道合伙人数码行家
关注
展开全部
class TeacherTest{
public static void main(String args[]){
Teacher s1=new Teacher("李四",123,20);
Teacher s2=new Teacher();
System.out.println("姓名:"+s1.getName()+"学号:"+s1.getId()+"年龄:"+s1.getAge());
System.out.println("姓名:"+s2.getName()+"学号:"+s2.getId()+"年龄:"+s2.getAge());
}
}
//改成
public static void main(String args[]){
Teacher s1=new Teacher("李四",123,20);
Teacher s2=new Teacher();
System.out.println("姓名:"+s1.getName()+"学号:"+s1.getId()+"年龄:"+s1.getAge());
System.out.println("姓名:"+s2.getName()+"学号:"+s2.getId()+"年龄:"+s2.getAge());
}
public static void main(String args[]){
Teacher s1=new Teacher("李四",123,20);
Teacher s2=new Teacher();
System.out.println("姓名:"+s1.getName()+"学号:"+s1.getId()+"年龄:"+s1.getAge());
System.out.println("姓名:"+s2.getName()+"学号:"+s2.getId()+"年龄:"+s2.getAge());
}
}
//改成
public static void main(String args[]){
Teacher s1=new Teacher("李四",123,20);
Teacher s2=new Teacher();
System.out.println("姓名:"+s1.getName()+"学号:"+s1.getId()+"年龄:"+s1.getAge());
System.out.println("姓名:"+s2.getName()+"学号:"+s2.getId()+"年龄:"+s2.getAge());
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一个java程序中只能有一个public的类,而static表示可以通过类名调用本方法,你的public类是Teacher,当然找不到主方法了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你文件名是不是TeacherTest.java 我怀疑的你文件名定义为了Teacher.java
将文件名改成TeacherTest.java 然后把Teacher这个类前面的public删掉
将文件名改成TeacherTest.java 然后把Teacher这个类前面的public删掉
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我猜类的名字是Teacher,你的main不在主类里,在TeacherTest里,把main方法放在主里
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询