class Book{
public void print(){
System.out.println("this ="+this);
}
}
public class TestDemo{
public static void main(String args[]){
Book booka=new Book();
System.out.println("booka = "+booka);
booka.print();
System.out.println("****************");
Book bookb=new Book();
System.out.println("bookb = "+bookb);
bookb.print();
}
}
this就是当前调用方法的对象之前出现的this.属性实际上就是当前对象中的属性,一定是堆内存保存的内容。
class A{
private B b;
public A(){
this.b=new B(this);
this.b.get();
}
public void print(){
System.out.println("hello world!");
}
}
class B{
private A a;
public B(A a){
this.a=a;
}
public void get(){
this.a.print();
}
}
public class TestDemo{
public static void main(String args[]){
A temp=new A();
}
}