Q25
Given:
String message1 = "Wham
bam!";
String message2 = new String("Wham bam!");
if (message1 == message2)
System.out.println("They match");
if
(message1.equals(message2))
System.out.println("They really match");
What is the
result?
A.
They match
They really match
They match
They really match
B.
They really match
They really match
C.
They match
They match
D.
Nothing Print
Nothing Print
E.
They really match
They really match
La risposta è B.
Infatti l'operatore (= =) compara i riferimenti e non i valori. Perciò, essendo message1 e message2 due riferimenti diversi l'operatore restituisce falso. Invece i valori sono uguali e quindi il metodo .equals restituisce vero.
riferimento : Operatore == e metodo .equals ()
They really match
They really match
La risposta è B.
Infatti l'operatore (= =) compara i riferimenti e non i valori. Perciò, essendo message1 e message2 due riferimenti diversi l'operatore restituisce falso. Invece i valori sono uguali e quindi il metodo .equals restituisce vero.
riferimento : Operatore == e metodo .equals ()
Nessun commento:
Posta un commento