Likes

Java Lab04_Ans2

Write a program to store the employee details, such as employee ID, name,designation.
In addition, the employee details should be display when the object of the class is printed.


Answer


public class Employee {
public int empID;
Public String empName;
Public String empDesg;
Public String empDept;

public Employee()  {

empID = 2132;
empName = "Kamal Sharma";
empDesg = "Manager";
empDept = "Admin";
}

public String toString() {
StringBuffer = new StringBuffer();
buffer.append("The Employee Details are: \n");
buffer.append("The Employee ID: "+ empID+ "\n");
buffer.append("The Employee Name: "+ empName+"\n");
buffer.append("The Employee Designation: "+ empDesg+"\n");
buffer.append("The Employee Department: "+ empDept+"\n");
return buffer.toString();
    }
public static void main(String[] args) {
Employee oobj = new Employee();
System.out.println(eobj);
    }
}

No comments: