-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavaClass_38.java
39 lines (34 loc) · 1.02 KB
/
JavaClass_38.java
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
class Employee{
int id;
int salary;
String name;
public void printDetails(){
System.out.println("My id is " + id);
System.out.println("and my name is "+ name);
}
public int getSalary(){
return salary;
}
}
public class JavaClass_38 {
public static void main(String[] args) {
System.out.println("This is our custom class");
Employee Alice = new Employee(); // Instantiating a new Employee Object
Employee bob = new Employee(); // Instantiating a new Employee Object
// Setting Attributes for Alice
Alice.id = 12;
Alice.salary = 34;
Alice.name = "";
// Setting Attributes for Bob
bob.id = 17;
bob.salary = 12;
bob.name = "bob Khandelwal";
// Printing the Attributes
Alice.printDetails();
bob.printDetails();
int salary = Alice.getSalary();
System.out.println(salary);
// System.out.println(alice.id);
// System.out.println(alice.name);
}
}