summary refs log tree commit diff stats
path: root/java/code
diff options
context:
space:
mode:
Diffstat (limited to 'java/code')
-rw-r--r--java/code/ParentWithTwoChildren.java60
1 files changed, 60 insertions, 0 deletions
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();
+    }
+}