Create a class EmpOverriding and Employee and create a displayName()

0

Assignment: Module 04

Create a class EmpOverriding and Employee and create a displayName()

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 

👉Create a package accesstest1 and accesstest2 under com.grazitti and create four classes on your own to explain the default, public, private and protected access specifiers 👈

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
✨ Updates