java吧 关注:1,249,460贴子:12,731,584
  • 6回复贴,共1

【新人】大家帮忙看看这个程序有木有什么问题?

只看楼主收藏回复

class Student{
int age;
String name;
static String schoolName;
public Student(int age,String name){
this.age=age;
this.name=name;
}
public void Introduce(){
System.out.println("大家好我叫"+name+",我今年"+age+"岁,来自"+schoolName+".");
}
}
public class Jieshao{
public static void main(String[] args){
Student.stu1=new Student(18,"小李");
Student.stu2=new Student(19,"小明");
Student.schoolName="哈佛";
stu1.Introduce();
stu2.Introduce();
}
}


IP属地:浙江1楼2015-04-23 22:04回复
    刚学Java2天,写了个程序,一直报错说找不到符号啊


    IP属地:浙江2楼2015-04-23 22:06
    回复
      然而十分钟过去了


      IP属地:浙江3楼2015-04-23 22:15
      回复
        static静态要用类来调用


        IP属地:浙江来自iPhone客户端6楼2015-04-23 22:35
        回复
          introduce方法不是静态方法 不能调用静态成员变量schoolName


          IP属地:新疆来自Android客户端7楼2015-04-23 22:41
          收起回复
            对头,有静态方法不能调用非静态成员变量,


            IP属地:湖南8楼2015-04-23 22:52
            回复