I am currently learning Java. Look at the code below:
package classtest1;
class ClassSuper
{
public Object myObject = new Object();
public ClassSuper(){}
}
public class ClassTest1 extends ClassSuper
{
public ClassTest1()
{
System.out.println("this.myObject.equals(super.myObject) return: " + this.myObject.equals(super.myObject));
System.out.println("this.myObject == (super.myObject) return: " + this.myObject == (super.myObject));
}
public static void main(String[] args)
{
ClassTest1 myClassTest1 = new ClassTest1();
}
}
the output is below:
run:
this.myObject.equals(super.myObject) return: true
false
BUILD SUCCESSFUL (total time: 0 seconds)
My question is that, why equals and "==" are not the same? Why output false when using "==". Will Subclass create a new copy myObject in memory?