JAVA初学者,小程序求解答?
Stu s = new Stu();//new一个Stu对象 class Stu{ int id; Stu f; Stu() { id = 0; f = this; //想用 f 指向刚 new 的这个对象 } }public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("hello\n"); Stu s = new Stu(); System.out.println(s.f.id);//用s.id会更直接些! }}class Stu{ int id; Stu f; Stu() { id = 3; f = this; //想用 f 指向刚 new 的这个对象 }}