From 6766b6479a1d30680c1eb59df4c4b720eb22ce1c Mon Sep 17 00:00:00 2001 From: Sudipto Mallick Date: Wed, 24 Jan 2024 16:44:31 +0000 Subject: Implement Java Assignment #15 and more java/{code/ParentWithTwoChildren.java, output/ParentWithTwoChildren.typ, text/ParentWithTwoChildren.typ}: Code, output and assignment text for Java assignment #15 java/state.sql: Update for Java assignment #15 java/template.typ: Allow for long program description to be left aligned and justified, instead of centered java/tobedone: Update to show assignment numbers (implicitly `rowid`) --- java/code/ParentWithTwoChildren.java | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 java/code/ParentWithTwoChildren.java (limited to 'java/code') diff --git a/java/code/ParentWithTwoChildren.java b/java/code/ParentWithTwoChildren.java new file mode 100644 index 0000000..20b04cb --- /dev/null +++ b/java/code/ParentWithTwoChildren.java @@ -0,0 +1,60 @@ +class Parent { + int id; + String name; + String address; + + Parent(int id, String name, String address) { + this.id = id; + this.name = name; + this.address = address; + } + + void display() { + String className = this.getClass().getSimpleName(); + System.out.println(className + ": ID: " + id + ", Name: " + name + ", Address: " + address); + } +} + +class ChildOne extends Parent { + int marks; + + ChildOne(int id, String name, String address, int marks) { + super(id, name, address); + this.marks = marks; + } + + @Override + void display() { + super.display(); + System.out.println(" Marks: " + marks); + } +} + +class ChildTwo extends Parent { + String qualification; + double salary; + + ChildTwo(int id, String name, String address, String qualification, double salary) { + super(id, name, address); + this.qualification = qualification; + this.salary = salary; + } + + @Override + void display() { + super.display(); + System.out.println(". Qualification: " + qualification + ", Salary: " + salary); + } +} + +class ParentWithTwoChildren { + public static void main(String[] args) { + Parent parent1 = new Parent(1, "John Doe", "123 Main St."); + ChildOne child1 = new ChildOne(2, "Jane Doe", "456 Elm St.", 85); + ChildTwo child2 = new ChildTwo(3, "Mike Smith", "789 Oak St.", "B.Tech", 50000); + + parent1.display(); + child1.display(); + child2.display(); + } +} -- cgit 1.4.1-2-gfad0 b534545a667a25994f845ecb3a4525a58b845'>doc/pydoc/ranger.gui.ui.html
blob: abd01711f845618eef739ebc871a2f629011b5fd (plain) (blame)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179