Java Practical No.18.pdf

  • Uploaded by: Meer Kukreja
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Java Practical No.18.pdf as PDF for free.

More details

  • Words: 209
  • Pages: 7
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:

Related Documents


More Documents from "Meer Kukreja"