Teacher.java
codice:
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();
}
}
}
Oppure
Employee.java
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);
}
}
Teacher.java
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();
}
}
}