-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.java
More file actions
74 lines (59 loc) · 1.61 KB
/
Person.java
File metadata and controls
74 lines (59 loc) · 1.61 KB
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
package CoreIdeas.inherent.Person;
public class Person {
// Fields
private String name;
private int age;
// Constructors
// Put attention: if we use inherent relation we must create a deafualt constractor at the root class
public Person() {
// default constructor
name = "";
age = 0;
}
public Person(String n, int a) {
// a = age from the user, n = name from the user
name = n;
age = a;
}
// Getters and setters
public String getName() {
return name;
}
public void setName(String n) {
// n = name from the user
name = n;
}
public int getAge() {
return age;
}
public void setAge(int a) {
// a = age from the user
age = a;
}
// Other Methods
@Override
public String toString() {
// returns a string with the name and age of the person
return "Name: " + name + "\nAge: " + age;
}
}
public static void main(String[] args) {
Person p = new Person(); // creats a new object of person with a difaulte constructor
p.setName("John");
p.setAge(25);
System.out.println(p.toString());
// Create a new Person object without the default constructor
//
//
//
//
// Create a new Student object with the default constructor
//
//
//
// Create a new Student object without the default constructor
//
//
//
}
}