-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHooman.java
More file actions
79 lines (61 loc) · 1.73 KB
/
Hooman.java
File metadata and controls
79 lines (61 loc) · 1.73 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
75
76
77
78
79
package classesandobject.part1;
public class Hooman {
// Field - 2 Class variables
public static final String SPECIES;
private static int objectCounter = 0; // can also be written inside static{}
// Field - 3 instance variables
private String name;
private int age;
private boolean isAdult;
//static initializers
static {
System.out.println("static initializers");
SPECIES = "Homo Sapiens"; // normally other calculation is performed. This is simple example
}
//instance initializers
{
System.out.println("instance initializer");
isAdult = false; // by default false though
}
//constructor 1
public Hooman() {
System.out.println("Constructor-1");
objectCounter++;
}
//constructor 2
public Hooman(String name, int age) {
System.out.println("Constructor-2");
this.name = name;
this.age = age;
isAdult = age >= 18;
objectCounter++;
}
// all methods are shown below
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
if(age < 0 || age < this.age) return;
this.age = age;
isAdult = (age>=18);
}
public boolean isAdult() {
return isAdult;
}
public static int getObjectCounter() {
return objectCounter;
}
public static void showSomeCharacter(){
System.out.println("General characteristics");
//System.out.println(name);//can't access name here
}
public void showSpecificCharacter(){
System.out.println("Name is => "+name);
}
}