- 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è
Is Java Pass by Value?
"Is Java pass by value or pass by reference?" is one of the most asked Java interview questions. This quiz answers it with real programs: you will see when a method's changes reach the caller and when they silently disappear.
Domanda di esempio
Domanda 1 di 10What does this print?
public class Main {
static void swap(String a, String b) {
String temp = a;
a = b;
b = temp;
}
public static void main(String[] args) {
String x = "left";
String y = "right";
swap(x, y);
System.out.println(x + " " + y);
}
}
Mostra la risposta
B. left right a and b are copies of the references in x and y. Swapping the copies inside the method does not touch the caller's variables, which is why a classic swap method is impossible in Java.
Cosa copre questo quiz
- Java always passes a copy of the value
- For objects, the copied value is the reference
- Mutating an object vs reassigning a parameter
- Why a swap method does not work
- Immutable types like
StringandIntegeras parameters
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.