Codice: Seleziona tutto
public class DemoStatic {
private int number;
// DemoStatic(): costruttore predefinito
public DemoStatic(int n) {
number = n;
}
// print1(): metodo di classe
static void print1(DemoStatic v) {
System.out.println(v.number);
}
// print2(): metodo di istanza
void print2() {
System.out.println(number);
}
}
Poi ho scritto quest'altra per utilizzare la precedente:
Codice: Seleziona tutto
public class ProvaDemoStatic {
// main(): punto di ingresso dell'applicazione
public static void main(String[] args) {
DemoStatic s = new DemoStatic(5);
DemoStatic t = new DemoStatic(10);
DemoStatic.print1(t);
s.print2();
}
}
Codice: Seleziona tutto
1. ERROR in ProvaDemoStatic.java (at line 10)
DemoStatic s = new DemoStatic(5);
^^^^^^^^^^
DemoStatic cannot be resolved to a type
----------
2. ERROR in ProvaDemoStatic.java (at line 10)
DemoStatic s = new DemoStatic(5);
^^^^^^^^^^
DemoStatic cannot be resolved to a type
----------
3. ERROR in ProvaDemoStatic.java (at line 11)
DemoStatic t = new DemoStatic(10);
^^^^^^^^^^
DemoStatic cannot be resolved to a type
----------
4. ERROR in ProvaDemoStatic.java (at line 11)
DemoStatic t = new DemoStatic(10);
^^^^^^^^^^
DemoStatic cannot be resolved to a type
----------
5. ERROR in ProvaDemoStatic.java (at line 13)
DemoStatic.print1(t);
^^^^^^^^^^
DemoStatic cannot be resolved
Ciao e grazie!
