What is the error in this java program? I want to print like : I Work (newline) I create apps (newline) I teach
class Employee{
protected void work(){
System.out.println("I Work ");
}
}
class Dev extends Employee{
public void work(){
System.out.println("I create apps ");
}
}
class Teacher extends Employee{
public void work(){
System.out.println("I teach");
}
}
public class inheritance{
public static void main(String[] args){
Employee E1 = new Employee();
Employee E2 = new Employee();
Employee E3 = new Employee();
E1.Employee();
E2.Dev();
E3.Teacher();
}
}
CodePudding user response:
class Employee{
String Name, Job;
protected void work(){
System.out.println("I Work ");
}
}
class Dev extends Employee{
public void work(){
System.out.println("I create apps ");
}
}
class Teacher extends Employee{
public void work(){
System.out.println("I teach");
}
}
public class inheritance{
public static void main(String[] args){
Employee E1 = new Employee();
Employee E2 = new Dev();
Employee E3 = new Teacher();
E1.work();
E2.work();
E3.work();
}
}
CodePudding user response:
Employee E1 = new Employee();
E1.work();
Employee E2 = new Dev();
E2.work();
Employee E3 = new Teacher();
E3.work();