- 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 & final
This Java quiz checks what static and final really mean for fields, methods, classes and variables. You will predict output with shared counters and static blocks, and spot code where static or final makes the compiler say no.
Domanda di esempio
Domanda 1 di 10What does this print?
public class Main {
static class Ticket {
static int count = 0;
int id;
Ticket() {
count++;
id = count;
}
}
public static void main(String[] args) {
Ticket a = new Ticket();
Ticket b = new Ticket();
Ticket c = new Ticket();
System.out.println(a.id + " " + Ticket.count);
}
}
Mostra la risposta
C. 1 3 count is static, so all tickets share one counter that reaches 3. id is an instance field, so a keeps the value it copied when it was created, 1.
Cosa copre questo quiz
- Static fields shared by all objects
- Why static methods cannot use instance fields
- Static initializer blocks and when they run
finalvariables, references and fieldsfinalclasses and constants
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.