-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClassDemo.java
More file actions
55 lines (49 loc) · 1.72 KB
/
ClassDemo.java
File metadata and controls
55 lines (49 loc) · 1.72 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
// S.O.L.I.D
// D - DRY - Donot Repeat Yourself
class Employee {
int id;
String name;
double salary;
String dept;
public void takeInput(int id, String name, String dept, double salary) {
this.id = id;
this.name = name;
this.dept = dept;
this.salary = salary;
}
public void showEmp() {
// java uses this keyword internally
// this = refers to current object
System.out.println("Emp ID : " + this.id);
System.out.println("Emp Name : " + this.name);
System.out.println("Emp Dept : " + dept);
System.out.println("Emp Salary : " + salary);
}
}
public class ClassDemo {
public static void main(String[] args) {
Employee emp = new Employee();
// emp.id = 101;
// emp.name = "John";
// emp.dept = "IT";
// emp.salary = 45000.00;
emp.takeInput(101, "John", "IT", 45000.00);
emp.showEmp();
// System.out.println("Emp ID : " + emp.id);
// System.out.println("Emp Name : " + emp.name);
// System.out.println("Emp Dept : " + emp.dept);
// System.out.println("Emp Salary : " + emp.salary);
// Object emp = new Employee();
Employee emp_2 = new Employee();
// emp_2.id = 102;
// emp_2.name = "Mac";
// emp_2.dept = "IT";
// emp_2.salary = 50000.00;
// System.out.println("Emp ID : " + emp_2.id);
// System.out.println("Emp Name : " + emp_2.name);
// System.out.println("Emp Dept : " + emp_2.dept);
// System.out.println("Emp Salary : " + emp_2.salary);
emp_2.takeInput(102, "Max", "IT", 60000.00);
emp_2.showEmp();
}
}