JAVA

PART -A

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7

PART-B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 PROGRAM B7 PROGRAM B8 . . .

7.

 
  
 
 
 
 
7.Consider class person with fields name, address and date of birth and methods read_data() and show() and another class employee inherited form person class with fields emp_id, date of join and salary and methods read() and show(). Write java program to implement the concept of single inheritance with method overriding concepts for the above classes.

 import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class P7{
public static void main(String[] args) {
System.out.println("ENTER PERSON DETAISL name:");
Person p1=new Person();
p1.read();
System.out.println("-------------------------");
p1.show();
System.out.println("-------------------------");
System.out.println("ENTER EMPLOYEE DETAILS WITH INHERITED properties:");
Employee e1=new Employee();
e1.read();
System.out.println("-------------------------");
e1.show();
System.out.println("-------------------------");


}

}

class Person{
  public String name;
   public String address;
    public String dateofbirth;

            public void read()
            {
                Scanner s=new Scanner(System.in);
               System.out.println("enter name:");
              name=s.next();
              System.out.println("enter address:");
              address=s.next();

              System.out.println("enter dateofbirth:");
              dateofbirth=s.next();
             }

            public void show(){
System.out.println("-------------- PERSON DETAILS---------------");
              System.out.println(" Name:"+name);
              System.out.println(" Address:"+address);
              System.out.println(" Date of birth:"+dateofbirth);  

            }
}

class Employee extends Person{
 private String empID;
   private int salary;
    private String dateofjoining;


        public void read()
            {
                Scanner s=new Scanner(System.in);
                System.out.println("enter name:");
              name=s.next();
              System.out.println("enter address:");
              address=s.next();

              System.out.println("enter dateofbirth:");
              dateofbirth=s.next();
               System.out.println("enter emp_ID:");
              empID=s.next();
              System.out.println("enter date of joining:");
              dateofjoining=s.next();

              System.out.println("enter SALARY:");
              salary=s.nextInt();
             }

            public void show(){
System.out.println("-------------- Employee DETAILS---------------");
              System.out.println(" Name:"+name);
              System.out.println(" Address:"+address);
              System.out.println(" Date of birth:"+empID);  
             System.out.println(" Employee ID:"+dateofbirth);
             System.out.println(" Salary:"+salary); 
            System.out.println(" Date of Joing:"+dateofjoining); 

            }
  
       
}