From Maha:
Satyavani, Please use the < pre > your code comes here < pre > to align your code. Also put the 'pre' tags without the space in bet < and >. Please edit your code to make it easy for others to read. class MyClass
{
static int maxElements;
MyClass(int maxElements)
{
this.maxElements = maxElements;
}
}
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 samevalues");
else
System.out.println("Objects have different values");
}
}
A) Compilation error at line 20. equals() method was not defined.
B) Compiles fine, runtime exception at line 20.
C) Prints "Objects have the same values".
D) Prints "Objects have different values";
I ran the code and found to my surprise ans is the out put. But equals() compares the contents of the object, so both the objects contain 100 then why is the output D? can some one clear my doubt?
[This message has been edited by maha anna (edited April 17, 2000).]