Welcome Guest | Sign in | Register
java.lang.class - Discussion Page For Q.2896 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > java.lang.class > Questions and Answers

Exercise:

Section 1

Q: 2. What will be the output of the program?

public class ObjComp
{
public static void main(String [] args )
{
int result = 0;
ObjComp oc = new ObjComp();
Object o = oc;

if (o == oc)
result = 1;
if (o != oc)
result = result + 10;
if (o.equals(oc) )
result = result + 100;
if (oc.equals(o) )
result = result + 1000;

System.out.println("result = " + result);
}
}
A. 1 B. 10
C. 101 D. 1101

Answer and Explanation

Answer:1101

Explanation:
Even though o and oc are reference variables of different types, they are both referring to the same object. This means that == will resolve to true and that the default equals() method will also resolve to true.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.