Java Practical No.19.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.19.pdf as PDF for free.

More details

  • Words: 237
  • Pages: 6
19.1) DEMONSTRATE THE USE OF INTERFACES TO IMPLEMENT THE CONCEPT OF MULTIPLE INHERITANCE. PROGRAM: import java.util.*; class student { Scanner s=new Scanner(System.in); int rn;

void get() { System.out.println("Enter the rollno:"); rn=s.nextInt(); } void put() { System.out.println("Rollno:"+rn); } } class test extends student { int part1,part2;

void get1() { System.out.println("Enter the marks of part1 and part2:"); part1=s.nextInt(); part2=s.nextInt(); }

void put1() { System.out.println("part 1:"+part1); System.out.println("part2:"+part2); } } interface sports { int sportswt=10; void put2(); } class result extends test implements sports { int total; void cal() { total=part1+part2; } void display() { System.out.println("Total:"+total); } public void put2() { System.out.println("Sports wicket:"+sportswt); } } class sportsDemo {

public static void main(String args[]) { result r=new result(); r.get(); r.put(); r.get1(); r.put1(); r.cal(); r.display(); r.put2(); } } OUTPUT:

19.2) DEVELOP A PROGRAM TO FIND AREA OF RECTANGLE AND CIRCLE USING INTERFACES. PROGRAM: import java.util.*; interface shape { Scanner s=new Scanner(System.in);

void get(); void put(); } class circle implements shape { int r; float pi=3.14f; float ar=0;

public void get() { System.out.println("Enter the radius of circle:"); r=s.nextInt(); } public void put() { ar=pi*r*r; System.out.println("Area of circle:"+ar+"sq cm"); } } class rectangle implements shape {

int len,bdth; float ar=0f;

public void get() { System.out.println("Enter the length and breadth:"); len=s.nextInt(); bdth=s.nextInt(); } public void put() { ar=len*bdth; System.out.println("Area of rectangle:"+ar+"sq cm"); } } class rDemo { public static void main(String args[]) { rectangle r=new rectangle(); r.get(); r.put();

circle c=new circle(); c.get(); c.put(); } }

OUTPUT:

Related Documents


More Documents from "Meer Kukreja"