Engineering Full Stack Apps with Java and JavaScript
Consider the following lines of code:
Integer i = new Integer(42); Long ln = new Long(42); Double d = new Double(42.0);
Which of the following options are valid?
Select 3 options
A. i == ln; B. ln == d; C. i.equals(d); D. d.equals(ln); E. ln.equals(42);
C, D, E
The concept to understand here is as follows - If the compiler can figure out that something can NEVER happen, then it flags an error.
In this question, the compiler knows that ln, i or d can never point to the same object in any case because they are references to different classes of objects that have no relation ( superclass/subclass ) between themselves.
Logged in users see lesser ads and get more features.
If you want to solve the questions together with the experts and understand the concepts better, please contact us using the contact form or WhatsApp numbers. Selected people get to do that without any additional charges.