Design an Employee class for reading and displaying employee information, the getInfo() and displayInfo() methods will be used respectively. Where getInfo() will be a private method. Used the Concept of Encapsulation to hide the data members, Employee Consist four data members.
/******************************************************************************
Design an Employee class for reading and displaying employee information,
the getInfo() and displayInfo() methods will be used respectively. Where getInfo() will be a private method.
the Concept of Encapsulation to hide the data members, Employee Consist four data members.
*******************************************************************************/
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Employee e=new Employee();
e.displayInfo();
}
}
class Employee{
private String fname;
private String lname;
private int empNo;
private int age;
private void getInfo(){
Scanner in =new Scanner(System.in);
System.out.print("First Name: ");
fname=in.next();
System.out.print("Second Name: ");
lname=in.next();
System.out.print("Employee number: ");
empNo=in.nextInt();
System.out.print("Age: ");
age=in.nextInt();
}
public void displayInfo(){
getInfo();
System.out.println("First Name: "+fname);
System.out.println("Second Name: "+lname);
System.out.println("Employee number: "+empNo);
System.out.println("Age: "+age);
}
}
Comments
Leave a comment