- Executores
-
Aprender
Aprender Python Exemplos executáveis, NumPy, pandas e mais Aprender IA / Machine LearningRedes neurais, ML e LLMs do zero Aprender C e C++ Ponteiros, memória, STL e C++ moderno Aprender C#Fundamentos, POO, LINQ, async e exercícios .NET Aprender MatplotlibGráficos de linha, barras, dispersão e pizza com visualizadores Aprender RustOwnership, traits, tratamento de erros e threads Aprender GoSlices, interfaces, goroutines e channels Algoritmos em Python Busca, ordenação, recursão e visualizações O(n) Algoritmos em C e C++ Compare implementações em C e C++ Programação para crianças Aprenda a programar brincando!
- QuizzesNovo
- DesafiosNovo
- Para professoresNovo
- Atualizações
- Me pague um café
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.
Pergunta de exemplo
Pergunta 1 de 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);
}
}
Mostrar a resposta
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.
O que este quiz cobre
- 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
Perguntas frequentes
Preciso de uma conta?
Não. Qualquer pessoa pode jogar. Entre para guardar seu XP, sequência, badges e histórico.
Posso refazer?
Pode. Sua melhor nota fica salva, e as perguntas e respostas são embaralhadas a cada vez.