public class Q19
{
public static void main(
String[] args)
{
MyClass a = new MyClass(100);
MyClass b = new MyClass(100);
if(a.equals(b))
System.out.println("Objects have the same values");
else
System.out.println("Objects have different values");
}
}
class MyClass
{
static int maxElements;
MyClass(int maxElements)
{
this.maxElements = maxElements;
// System.out.println("value:" +this.maxElements); the value is 100 for both a and b
}
}
The value for both a and b is 100 . When equals method gets executed it prints "Objects have different values". Why?.