-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD4-3.txt
72 lines (66 loc) · 2.05 KB
/
D4-3.txt
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
class Person{
private int salary = 5000;
public String name = "Jack";
protected int age = 24;
String email = "[email protected]";
public void display(){
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Email: " + email);
System.out.println("Salary: " + salary);
}
}
class Employee extends Person {
public void display(){
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Email: " + email);
}
}
class Customer {
public void display(){
Person p = new Person();
System.out.println("Name: " + p.name);
System.out.println("Age: " + p.age);
System.out.println("Email: " + p.email);
}
}
class Execute{
public static void main (String[] args) {
Person p = new Person();
Employee e = new Employee();
Customer c = new Customer();
System.out.println("******************************");
System.out.println("Person Class display method.");
System.out.println("******************************");
p.display();
System.out.println("******************************");
System.out.println("Employee Class display method.");
System.out.println("******************************");
e.display();
System.out.println("******************************");
System.out.println("Customer Class display method.");
System.out.println("******************************");
c.display();
}
}
Output:
******************************
Person Class display method.
******************************
Name: Jack
Age: 24
Email: [email protected]
Salary: 5000
******************************
Employee Class display method.
******************************
Name: Jack
Age: 24
Email: [email protected]
******************************
Customer Class display method.
******************************
Name: Jack
Age: 24
Email: [email protected]