Assignment: Module 04
![]() |
Create a class EmpOverriding and Employee and create a displayName()
Create a displayName() in both the classes (overriding methods)
Make employee class is a super class of empoverriding class. Display the empNames of the both classes using super keyword and call the methods accordingly.
Output:
Vishal
Varun
class Employee {
String empName = "Vishal";
public void displayName() {
System.out.println(empName);
}
}
class EmpOverriding extends Employee {
String empName = "Varun";
@Override
public void displayName() {
System.out.println(empName);
}
}
public class Main {
public static void main(String[] args) {
EmpOverriding eo = new EmpOverriding();
eo.displayName();
System.out.println(", ");
Employee e = new Employee();
e.displayName();
}
}
Output:
Varun
Vishal