- 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: Static vs Instance
This Java quiz checks how static fields, methods and blocks differ from instance members. You will predict shared counters, see when static blocks run and find out why static methods are hidden, not overridden.
Domanda di esempio
Domanda 1 di 10What does this print?
public class Main {
static class Counter {
static int total = 0;
int mine = 0;
Counter() {
total++;
mine++;
}
}
public static void main(String[] args) {
Counter a = new Counter();
Counter b = new Counter();
Counter c = new Counter();
System.out.println(Counter.total + " " + c.mine);
}
}
Mostra la risposta
B. 3 1 There is one total for the whole class, so every constructor call adds to the same counter. Each object gets its own mine, which starts at 0 and is incremented once.
Cosa copre questo quiz
- Static fields shared by every object
- What a static method can and cannot access
- When static initializer blocks run
- Static method hiding vs instance method overriding
- Static nested classes vs inner classes
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.