Write a class EmpConsOver a display name and number using display() and assign the values using constructors. Use objects to call the methods and pass the parameters to the constructors accordingly.

0

Assignment: Module 03- Part 03

Write a class EmpConsOver a display name and number using display() and assign the values using constructors. Use objects to call the methods and pass the parameters to the constructors accordingly.
Assignment: Module 03- Part 03

Write a class EmpConsOver a display name and number using display() and assign the values using constructors. Use objects to call the methods and pass the parameters to the constructors accordingly.

Output: 

Employee name:Akil

Employee no:101

Employee name:Arun

Employee no:102

Employee name:Rajesh

Employee no:103

Employee name:Vishal

Here is the code for an EmpConsOver class that displays the name and number of employees using the display() method and assigns the values using constructors:


class EmpConsOver {
    int empNumber;
    String empName;
  
    EmpConsOver(String name, int num) {
        empName = name;
        empNumber = num;
    }
  
    void display() {
        System.out.println("Employee name: " + empName);
        System.out.println("Employee no: " + empNumber);
    }
  
    public static void main(String args[]) {
        EmpConsOver obj1 = new EmpConsOver("Akil", 101);
        EmpConsOver obj2 = new EmpConsOver("Arun", 102);
        EmpConsOver obj3 = new EmpConsOver("Rajesh", 103);
        EmpConsOver obj4 = new EmpConsOver("Vishal", 104);
        obj1.display();
        obj2.display();
        obj3.display();
        obj4.display();
    }
}   

And here is the output:



Employee name: Akil
Employee no: 101
Employee name: Arun
Employee no: 102
Employee name: Rajesh
Employee no: 103
Employee name: Vishal
Employee no: 104   

👉Write a class ConstThisOver and its default constructor to call the parameterized constructor to display the employee number. 👈

Post a Comment

0Comments
Post a Comment (0)

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

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