Come mai c'è questo errore?codice:public class Employee{ int age; String firstname; String lastname; public Employee(){ // noargs } public Employee(int age, String firstname, String lastname){ this.age=age; this.firstname=firstname; this.lastname=lastname; } public void showDetails(){ System.out.println("Dipendente: " + firstname + " " + lastname + "\nEta: " + age); } public class Teacher extends Employee{ String school; double salary; public Teacher(int age, String firstname, String lastname, String school, double salary){ super(age,firstname,lastname); this.school=school; this.salary=salary; } public void showMoreDetails(){ System.out.println("He/She is teaching in " + school + " school.\nHis/Her salary is " + salary+ " €"); } public void teach(String subject){ System.out.println("Teacher is teaching "+subject); } public static void main(String[] args){ Employee e1 = new Employee(23,"Mr.","Rossi"); e1.showDetails(); Teacher t1 = new Teacher(60,"Mrs.","Bianchi","ITIS",1030.5); t1.showDetails(); t1.showMoreDetails(); } } }
Inoltre, se levo 'static' dal main compila correttamente, ma all'esecuzione genera questa eccezione:codice:Employee.java:40: non-static variable this cannot be referenced from a static context Teacher t1 = new Teacher(60,"Mrs.","Bianchi","ITIS",1030.5); ^ Employee.java:37: inner classes cannot have static declarations public static void main(String[] args){ ^
Exception in thread "main" java.lang.NoSuchMethodError: main
Per la istanziazione/visualizzazione dovrei ricorrere a una classe ausiliaria?

Rispondi quotando