Java Programming - Java.lang Class - Discussion
|
|
|
|
Read more:"Life is like riding a bicycle. To keep your balance you must keep moving."
- Albert Einstein
|
| 27. |
What will be the output of the program?
String s = "hello";
Object o = s;
if( o.equals(s) )
{
System.out.println("A");
}
else
{
System.out.println("B");
}
if( s.equals(o) )
{
System.out.println("C");
}
else
{
System.out.println("D");
}
- A
- B
- C
- D
|
| [A]. |
1 and 3 | | [B]. |
2 and 4 | | [C]. |
3 and 4 | | [D]. |
1 and 2 |
Answer: Option C
Explanation:
No answer description available for this question.
|
|
Hrishi said:
(Thu, Jun 24, 2010 09:24:36 AM)
|
|
| |
| I want to learn basic of java upto multithreading. |
|
Mammu said:
(Mon, Feb 21, 2011 08:06:39 AM)
|
|
| |
| Please anybody explain that logic. |
|
Drishti said:
(Mon, Aug 29, 2011 12:54:48 AM)
|
|
| |
public boolean equals(Object obj)
Indicates whether some other object is "equal to" this one.
It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true. |
|
Srikanth said:
(Fri, Dec 16, 2011 06:39:02 PM)
|
|
| |
.equals() is used for content comparison in String.
So String creates one object of scp with reference of s.
Here String reference is assigns to Object.
So Object and String references are both poining to same content "hello".
The (o.equals(s))and (s.equals(o) checks content of 's' and 'o'.
The content is same it returns True. |
|
Amey said:
(Mon, Mar 19, 2012 08:56:17 PM)
|
|
| |
| Here, 'o' and 's' refers to the same object. Hence, o.equals(s) ,s.equals(o) evaluates to true. |
|
|