0% found this document useful (0 votes)
5 views2 pages

JPR 9

The document demonstrates the use of interfaces in Java to implement multiple inheritance by defining two interfaces: 'rectangle' and 'circle'. It provides two code examples where the 'Area' class implements these interfaces to calculate the area of a rectangle and a circle. The second example shows an extension of the 'rectangle' interface by the 'circle' interface, allowing for a more streamlined implementation.

Uploaded by

shindearyan226
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

JPR 9

The document demonstrates the use of interfaces in Java to implement multiple inheritance by defining two interfaces: 'rectangle' and 'circle'. It provides two code examples where the 'Area' class implements these interfaces to calculate the area of a rectangle and a circle. The second example shows an extension of the 'rectangle' interface by the 'circle' interface, allowing for a more streamlined implementation.

Uploaded by

shindearyan226
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Demonstrate the use of interfaces to implement the concept of


multiple inheritance.(Attach the code at the end).

import java.util.*;
interface rectangle{
void aor();
}
interface circle{
void aoc();
}
class Area implements rectangle, circle{
final double pi = 3.14159;
double radius, len, bre;
Scanner sc = new Scanner(System.in);
public void aor(){
System.out.println("Enter Length and Breadth: ");
len = sc.nextDouble();
bre = sc.nextDouble();
}
public void aoc(){
System.out.println("Enter radius: ");
radius = sc.nextDouble();
}
public void display(){
System.out.println("Area of Circle: " +(pi*radius*radius));
System.out.println("Area of Rectangle: " +(len*bre));
}
public static void main(String[] args){
Area a1 = new Area();
a1.aor();
a1.aoc();
a1.display();
}
}

OUTPUT:
5. Develop a program to find area of rectangle and circle using
interfaces.

import java.util.*;
interface rectangle{
void aor();
}
interface circle extends rectangle{
void aoc();
}
class Area implements circle{
final double pi = 3.14159;
double radius, len, bre;
Scanner sc = new Scanner(System.in);
public void aor(){
System.out.println("Enter Length and Breadth: ");
len = sc.nextDouble();
bre = sc.nextDouble();
System.out.println("Area of Rectangle: " +(len*bre));
}
public void aoc(){
System.out.println("Enter radius: ");
radius = sc.nextDouble();
System.out.println("Area of Circle: " +(pi*radius*radius));
}
public static void main(String[] args){
Area a1 = new Area();
a1.aor();
a1.aoc();
}
}

OUTPUT:

You might also like