- Esecutori
-
Impara
Impara Python Esempi eseguibili, NumPy, pandas e altro Impara l'IA / Machine LearningReti neurali, ML e LLM da zero Impara C e C++ Puntatori, memoria, STL e C++ moderno Impara C#Fondamenti, OOP, LINQ, async ed esercizi .NET Impara MatplotlibGrafici a linee, barre, dispersione e torta con visualizzatori Impara RustOwnership, trait, gestione degli errori e thread Impara GoSlice, interfacce, goroutine e canali Algoritmi Python Ricerca, ordinamento, ricorsione e visualizzazioni O(n) Algoritmi C e C++ Confronta le implementazioni in C e C++ Programmazione per bambini Impara a programmare giocando!
- QuizNuovo
- SfideNuovo
- Per docentiNuovo
- Aggiornamenti
- Offrimi un caffè
Quiz di Java: Autoboxing & Wrapper Classes
This hard Java quiz is about wrapper classes like Integer and Long and the automatic boxing between them and primitives. It covers the classic interview gotchas: the Integer cache from -128 to 127, NullPointerException from unboxing, equals() across types and List.remove() with ints.
Domanda di esempio
Domanda 1 di 10What does this print?
public class Main {
public static void main(String[] args) {
Integer a = 127, b = 127;
Integer c = 128, d = 128;
System.out.println((a == b) + " " + (c == d));
}
}
Mostra la risposta
B. true false Autoboxing calls Integer.valueOf(), which returns cached objects for -128 to 127, so a and b are the same object. 128 is outside the cache, so c and d are different objects and == is false.
Cosa copre questo quiz
- The
Integercache and==on wrappers - Unboxing
nulland the ternary trap equals()betweenLongandIntegerlist.remove(int)vslist.remove(Object)- Wrapper keys in maps
Domande frequenti
Serve un account?
No. Chiunque può giocare. Accedi per salvare XP, serie, badge e cronologia.
Posso rifarlo?
Sì. Il tuo miglior punteggio resta salvato, e domande e risposte vengono mescolate ogni volta.