Skip to content

Commit 616dfb0

Browse files
Update Person_2.java
1 parent f746e6d commit 616dfb0

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/Person_2.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
package task2;
2+
23
// Question 1.4
3-
// creating base class person with attributes name and age
4-
public class Person_2{
4+
// Creating base class Person_2 with attributes name and age
5+
public class Person_2 {
56
String name;
67
int age;
78

8-
// creating parameterised constructor for person class
9-
public Person(String name, int age) {
9+
// Correct constructor name (must match class name)
10+
public Person_2(String name, int age) {
1011
this.name = name;
1112
this.age = age;
1213
}
1314

14-
public static void main(String[] args){
15-
// creating an object
16-
Employee e = new Employee("tony", 24,11000000,1234567);
15+
public static void main(String[] args) {
16+
// Creating an object
17+
Employee e = new Employee("tony", 24, 11000000, 1234567);
1718
System.out.println(e);
18-
19-
}
2019
}
20+
}
2121

22-
23-
class Employee extends Person{
22+
// Updated Employee to extend Person_2
23+
class Employee extends Person_2 {
2424
int employeeID;
2525
float salary;
26-
// using super keyword to initialise the attributes of parent class
26+
27+
// Using super keyword to initialize the attributes of parent class
2728
public Employee(String name, int age, float salary, int employeeID) {
2829
super(name, age);
2930
this.salary = salary;
@@ -40,6 +41,3 @@ public String toString() {
4041
'}';
4142
}
4243
}
43-
44-
45-

0 commit comments

Comments
 (0)