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

OOPS With Java-1

The document presents a Java program that demonstrates method overloading by calculating the area of different shapes (circle, rectangle, square, triangle) based on user input. It includes a class 'Area' with multiple 'area' methods for different parameters and a main class 'AreaMenujava' that handles user interaction. The program prompts the user to choose a shape and enter the necessary dimensions to compute and display the area.

Uploaded by

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

OOPS With Java-1

The document presents a Java program that demonstrates method overloading by calculating the area of different shapes (circle, rectangle, square, triangle) based on user input. It includes a class 'Area' with multiple 'area' methods for different parameters and a main class 'AreaMenujava' that handles user interaction. The program prompts the user to choose a shape and enter the necessary dimensions to compute and display the area.

Uploaded by

crazyiadaa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

EXPERIMENT 3

WAP to implement the concept of method overloading and method


overriding. And Abstract Class.

CODE:

import [Link];

public class Area {


final double pi = 3.14;
Scanner sc = new Scanner([Link]);

void area(double r) {
double area = pi * r * r;
[Link](area + " is the area of circle");
}

void area(double l, double b) {


double area = l * b;
[Link](area + " is the area of rectangle");
}

void area(int s) {
double area = s * s;
[Link](area + " is the area of square");
}

void area(double b, double h) {


double area = 0.5 * b * h;
[Link](area + " is the area of triangle");
}
}

class AreaMenujava {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
Area area = new Area();

[Link]("Choose shape to calculate area:");


[Link]("1. Circle");
[Link]("2. Rectangle");
[Link]("3. Square");
[Link]("4. Triangle");

[Link]("Enter your choice: ");


int choice = [Link]();
switch (choice) {
case 1:
[Link]("Enter radius: ");
double r = [Link]();
[Link](r);
break;

case 2:
[Link]("Enter length: ");
double l = [Link]();
[Link]("Enter breadth: ");
double b = [Link]();
[Link](l, b);
break;

case 3:
[Link]("Enter side: ");
int s = [Link]();
[Link](s);
break;

case 4:
[Link]("Enter base: ");
double base = [Link]();
[Link]("Enter height: ");
double h = [Link]();
[Link](base, h);
break;

default:
[Link]("Invalid choice!");
}
}
}

OUTPUT:

You might also like