-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestEmployeeCopy.java
65 lines (55 loc) · 1.43 KB
/
TestEmployeeCopy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.Scanner;
class Employee
{
private String name;
private int e_id;
private float salary;
private boolean status;
Employee()
{
name="Test"; //Default Constructure Definition
e_id=0;
salary=10000.50;
status=false;
}
Employee(String name, int e_id, float salary, boolean status)
{
this.name=name; //Parameterised Constructor
this.e_id=e_id;
this.salary=salary;
this.status=status;
}
Employee(Employee e) //Copy Constructor
{
name=e.name;
e_id=e.e_id;
salary=e.salary;
status=e.status;
}
void getData()
{
System.out.println("Name:"+name+"\nEmp Id:"+e_id+"\nSalary:"+salary+"\nStatus:"+status);
}
}
/*** Main Class***/
class TestEmployeeScan
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter Name (String) of Employee: " );
String name=sc.nextLine();
System.out.println("Enter Employee ID (Integer) of Employee: " );
int e_id=sc.nextInt();
System.out.println("Enter Salary (Float) of Employee: " );
float salary=sc.nextFloat();
System.out.println("Enter Working Satus (Boolean) of Employee: " );
boolean status=sc.nextBoolean());
Employee e1 = new Employee(name,e_id,salary,status);
Employee e1_backup = new Employee(e1); // Call to Copy Construcutor
System.out.println("\n\n Details of Employee:"+e.name );
e.getData();
System.out.println("\n\n Backup Details of Employee:"+e.name );
e.getData();
}
}