-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGettersSetters.java
More file actions
48 lines (30 loc) · 847 Bytes
/
GettersSetters.java
File metadata and controls
48 lines (30 loc) · 847 Bytes
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
class Person {
String name;
int age;
void speak() {
System.out.println("Your name: " + name);
}
int Retirement() {
int yearsLeft = 62 - age;
return yearsLeft;
}
int getAge() {
return age;
}
String getName() {
return name;
}
}
public class App {
public static void main(String[] args) {
Person person1 = new Person();
person1.name = "xyz";
person1.age = 45;
int years = person1.Retirement();
System.out.println("Years till retirements " + years);
int age = person1.getAge();
String name = person1.getName();
System.out.println("Name is: " + name);
System.out.println("Age is: " + age);
}
}