ysheng
发贴: 72
积分: 2
|
于 2003-09-17 13:13
public class TestClassP{
public static void main(String[] args){ TestClassP tp = new TestClassP(); Student stu = new Student("Jerry",30); System.out.println("name="+stu.name); System.out.println("age="+stu.age);
tp.setStudent(stu); System.out.println("name="+stu.name); System.out.println("age="+stu.age); }//off main
public void setStudent(Student stu){ stu.name = "Tom"; stu.age = 28; // Student stu1 = new Student("Tom",28)' // stu = stu1;
// stu.name = stu1.name; // stu.age = stu1.age; }
class Student{ public String name; public int age;
public Student(String name, int num){ this.name = name; this.age = age; } }//off Student }
编译错误: TestClassP.java:5: non-static variable this cannot be referenced from a static context Student stu = new Student("Jerry",30);
|