-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain1.java
More file actions
44 lines (35 loc) · 1.05 KB
/
Main1.java
File metadata and controls
44 lines (35 loc) · 1.05 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
package OOPSinJava;
class Person {
protected String name;
protected int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public void displayDetails() {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
}
}
class Employee extends Person {
private int employeeID;
private double salary;
public Employee(String name, int age, int employeeID, double salary) {
super(name, age); // Call the constructor of the superclass (Person)
this.employeeID = employeeID;
this.salary = salary;
}
public void displayEmployeeDetails() {
System.out.println("Employee ID: " + employeeID);
System.out.println("Salary: $" + salary);
}
}
public class Main1 {
public static void main(String[] args) {
Employee employee = new Employee("Vijay", 25, 12345, 50000.0);
System.out.println("Person Details:");
employee.displayDetails();
System.out.println("\nEmployee Details:");
employee.displayEmployeeDetails();
}
}