-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFClass21.java
60 lines (55 loc) · 1.47 KB
/
FClass21.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
import java.util.*;
class Employee
{
String eid;
String ename;
String eprojects[];
public Employee(Employee e)
{
this.eid = e.eid;
this.ename = e.ename;
this.eprojects = new String[e.eprojects.length];
for(int i=0; i< e.eprojects.length;i++) {
this.eprojects[i] = e.eprojects[i];
}
}
public Employee(String id, String name, String[] projects)
{
this.eid = id;
this.ename = name;
this.eprojects = projects;
}
public void display()
{
System.out.println("id:"+eid);
System.out.println("name:"+ename);
System.out.println("projects:");
for(String s : eprojects){
System.out.print(s+":");
}
System.out.print("\n");
}
public void mutator()
{
this.ename = "Mr "+ this.ename;
this.eprojects[0] = null;
}
}
public class FClass21
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
String project[] = {"P001","P002","P003"};
//Enter the id of employee
String id = s.nextLine();
//Enter the name of employee
String name = s.nextLine();
Employee e1 = new Employee(id,name,project);
Employee e2 = new Employee(e1);
//The copy constructor must copy all the data members.
e1.mutator();
e2.display();
s.close();
}
}