18.1) Develop a program to implement the multiple inheritance. PROGRAM: import java.util.*; class person { Scanner s=new Scanner(System.in); String name,gender; int age;
void get() { System.out.println("Enter the Name:"); name=s.next(); System.out.println("Enter the Age:"); age=s.nextInt(); System.out.println("Enter the Gender:"); gender=s.next(); } void put() { System.out.println("Name:"+name); System.out.println("Age:"+age); System.out.println("Gender:"+gender); } } class employee extends person {
String company; float salary; int emp_id;
void get1() { get(); System.out.println("Enter the Emp_id:"); emp_id=s.nextInt(); System.out.println("Enter the Company:"); company=s.next(); System.out.println("Enter the Salary:"); salary=s.nextFloat(); } void put1() { put(); System.out.println("Emp_id:"+emp_id); System.out.println("Company:"+company); System.out.println("Salary:"+salary); }
} class programmer extends employee { int NoOfProgKnow;
void get2() { get1(); System.out.println("Enter the No Of Program Knows:"); NoOfProgKnow=s.nextInt(); } void put2() { put1(); System.out.println("No Of Program Knows:"+NoOfProgKnow); } } class personDemo { public static void main(String args[]) { programmer p=new programmer(); p.get2(); } }
OUTPUT:
18.2) Develop a program to calculate the room area and volume to illustrate the concept of single inheritance. PROGRAM: import java.util.*; class shape { Scanner s=new Scanner(System.in); int len,wid,dep;
void get() { System.out.println("Enter the length:"); len=s.nextInt(); System.out.println("Enter the Width:"); wid=s.nextInt(); System.out.println("Enter the depth:"); dep=s.nextInt(); } } class room extends shape { int area,vol;
void get1() { area=len*wid; System.out.println("Area of room:"+area);
vol=len*wid*dep; System.out.println("Volume:"+vol); }
} class roomDemo { public static void main(String args[]) { room r=new room(); r.get(); r.get1(); } } OUTPUT: