Menu
Topics Index
...
`

Equals2452


If you need explanation Read this topic

If you need Answer Take test on this topic

Equals2452
What will be the output of the following program?
public class IsEquals {
    public static void main(String[] args) {
        A i = new A(10);
        A j = i;
        boolean result = i.equals(j) ? true : false;
        System.out.println(result);
    }
}
class A {
    public A(int j) {
        i = j;
    }
    int i;
}

A. true
B. false
C. Compilation Error
D. Runtime Error
Topic: Object As A Super Class In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

A
as there are two objects created for class A and the object 'j' is pointing to 'i' and in the condition they both are evaluated to true.

Posted by Bhalkiker Badrinath    2014-01-24 03:46:56


ans is C. declaration error because i is not initialised in class A

Posted by Nanda Kishore    2014-01-24 04:33:33


Ans:-)A because here we are creating two objects first object reference is assigned to j.so equals() compares content so I,J both contains 10 so it returns "true"

Posted by Rajashekar Chelpuri    2014-01-24 07:00:27


Congratulations Bhalkiker Badrinath. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-01-27 04:07:47


© meritcampus 2019

All Rights Reserved.

Open In App