I have doubt in java object creation. The below code says that object created by new keyword and this keyword are same. But why we cant use this keyword to call non static methods of other class in main method but we can use object reference of new keyword to call methods of other class in main method. The output is same of below code that means the object created by both is same i think.
class A5 {
void m() {
System.out.println(this); //prints same reference ID
}
public static void main(String args[]) {
A5 obj=new A5();
System.out.println(obj); //prints the reference ID
obj.m();
}
}
output: A5@22b3ea59
A5@22b3ea59