IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C++ Programming C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

Java Programming - Java.lang Class - Discussion

@ : Home > Java Programming > Java.lang Class > Finding the output - 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"); 
}
  1. A
  2. B
  3. C
  4. 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.

Write your comments here:
Name *:     Email:


© 2008-2013 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!