Ho questo cod:
codice:import java.util.*; /* * La classe astratta di prova */ abstract class ATest { abstract void saluto(); } /* * L'interfaccia di prova */ interface IProva { int incr(); } /* * La classe Base che implementa IProva */ class Test implements IProva extends ATest { private String nome; public static int get_cont; public static int set_cont; public static int cont; public String getNome() { System.out.println("~~ GetNome Invocato: Chiamata " + get_cont +" ~~ \n"); get_cont++; return nome; } public String setNome(String nm) { System.out.println("~~ SetNome Invocato: Chamata " + set_cont +" ~~ \n"); this.nome = nm; set_cont++; return this.nome; } public Test() { System.out.println("~~ Test Invocato ~~ \n"); } public int incr() { return cont++; } public void saluto() { System.out.println("Ciao da Test\n"); } } /* * La classe derivate che estende Test e implementa IProva */ class Test2 extends Test implements IProva { public static int conts; public Test2() { System.out.println("~~ Test2 Invocato ~~ \n"); } public int incr() { return conts++; } public void saluto() { System.out.println("Ciao da Test2\n"); } } /* * La classe princ che contiene il main() */ class Prova { public static void main(String[] args) { Test ts = new Test(); Test2 tt = new Test2(); String nom = "Luca"; String nom2 = "Erica"; ts.setNome(nom); System.out.println("Il mio nome: " + ts.getNome() + "\n"); } }
Ma Mi da:
Why?--------------------Configuration: sdk <Default>--------------------
C:\Progetti\Java\Prova.java:17: '{' expected
class Test implements IProva extends ATest {
^
C:\Progetti\Java\Prova.java:81: '}' expected
}
^
C:\Progetti\Java\Prova.java:17: Test should be declared abstract; it does not define incr() in Test
class Test implements IProva extends ATest {
^
C:\Progetti\Java\Prova.java:53: inner classes cannot have static declarations
public static int conts;
^
C:\Progetti\Java\Prova.java:74: non-static variable this cannot be referenced from a static context
Test2 tt = new Test2();
^
C:\Progetti\Java\Prova.java:77: cannot resolve symbol
symbol : method setNome (java.lang.String)
location: class Test
ts.setNome(nom);
^
C:\Progetti\Java\Prova.java:78: cannot resolve symbol
symbol : method getNome ()
location: class Test
System.out.println("Il mio nome: " + ts.getNome() + "\n");
^
C:\Progetti\Java\Prova.java:72: inner classes cannot have static declarations
public static void main(String[] args) {
^
8 errors
Process completed.