-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.java.java
More file actions
56 lines (39 loc) · 1.21 KB
/
Employee.java.java
File metadata and controls
56 lines (39 loc) · 1.21 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
package JavaSessions;
public class Employee {
//class --> blueprint/template of all objects
//class is a concept
//class template --> create the object
//class vars: will be common for all the objects, but their values will be different
//class properties
String name;
int age;
double salary;
boolean isActive;
public static void main(String[] args) {
String name = "Peter";//local variable
System.out.println(name);
//create the object: use new keyword
Employee e1 = new Employee();
e1.name = "Tom";
e1.age = 20;
e1.salary = 23.44;
e1.isActive = true;
System.out.println(e1.name);
System.out.println(e1.age);
System.out.println(e1.salary);
System.out.println(e1.isActive);
Employee e2 = new Employee();
e2.name = "Naveen";
e2.isActive = false;
System.out.println(e2.name + " "+ e2.age + " " + e2.salary + " " + e2.isActive);
e2.salary = 12.22;
System.out.println(e2.name + " "+ e2.age + " " + e2.salary + " " + e2.isActive);
//no ref objects
new Employee().name = "Lisa";
new Employee().age = 21;
Employee e5 = new Employee();
e5 = null; //null ref objects
System.out.println(e5.name);//NPE
System.gc(); //wil try to destroy 3 objects
}
}