-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathF7 Copy constructor.java
77 lines (61 loc) · 1.62 KB
/
F7 Copy constructor.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
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Copy constructor
*/
public class App {
public static void main(String[] args) {
Person p1 = new Person("Subhranhsu Choudhury", "Indian", "26/08/2003", 5);
System.out.println(p1.getname());
p1.setname("Baishakhi Das");
System.out.println(p1.getname());
Person p2 = new Person(p1); // copy constructor (p2=p1)
System.out.println(p2.getname());
}
}
/*
// in Person.java file
public class Person {
private String name;
private String nationality;
private String dob;
private int seatNumner;
public Person (String name,String nationality,String dob,int seatNumner) {
this.name = name;
this.nationality = nationality;
this.dob = dob;
this.seatNumner = seatNumner;
}
// getters
public String getname() {
return this.name;
}
public String getnationality() {
return this.nationality;
}
public String getdob() {
return this.dob;
}
public int getseatNumber() {
return this.seatNumner;
}
// setter
public void setname(String name) {
this.name = name;
}
public void setnationality(String natio) {
this.nationality = natio;
}
public void setdob(String dob) {
this.dob = dob;
}
public void setseatnumber(int seatnumber) {
this.seatNumner = seatnumber;
}
// copy constructor #############
public Person(Person source){
this.name = source.name;
this.nationality = source.nationality;
this.dob = source.dob;
this.seatNumner = source.seatNumner;
}
}
*/