• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

A trick Question

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Integer i = new Integer (42);
Long 1 = new Long (42);
Double d = new Double (42.0);
Which two expressions evaluate to True? (Choose Two)
A.(i ==1)
B.(i == d)
C.(d == 1)
D.(i.equals (d))
E.(d.equals (i))
F.(i.equals (42))


i got answer until i compile and refer JDK API Documents.So notice such question.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by WiLL Tao:

i got answer until i compile and refer JDK API Documents.So notice such question.


Since it's a trick question, do you mean true, instead of True?
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First the name of the reference variable of type Long is l (el) not 1 (one). The latter is not a legal identifier.
Then, A, B and C all yield false since all reference variables are different (created with new).
D and E yield false too since Double.equals() expects an argument of type Double and Integer.equals() expects an argument of type Integer.
F is false too since equals() expects an object and not a primitive.
To summarize, statements A B C F will not compile. D E compile and when run yield false.
So this question is wrong.
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only D and E are correct statement but return false...rests are wrong statements....So no statement return true.
Believe me, u'll not face such weird question in the real exam. I found so many such weird question in the mock test...but did'nt face in the real exam....
But, really, these are need for self development and confidence
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic