Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
5.0k views
in Computer by (48.9k points)
closed by

A superclass Perimeter has been defined to calculate the perimeter of a parallelogram. Define a subclass Area to compute the area of the parallelogram by using the required data members of the superclass. The details are given below:

Class name: Perimeter 

Data members/instance variables: 

a: to store the length in decimal 

b: to store the breadth in decimal 

Member functions: 

Perimeter (…): parameterized constructor to assign values to data members double Calculate(): calculate and return the perimeter of a parallelogram is 2* (length + breadth) 

void show(): to display the data members along with the perimeter of the parallelogram

Class name: Area 

Data members/instance variables: 

h: to store the height in decimal 

area: to store the area of the parallelogram 

Member functions: 

Area(…): parameterized constructor to assign values to data members of both the 

classes 

void doarea(): compute the area as (breadth * height) 

void show(): display the data members of both classes along with the area and 

perimeter of the parallelogram. 

Specify the class Perimeter giving details of the constructor (…), double Calculate 

and void show (). Using the concept of inheritance, specify the class Area giving details of the constructor (…), void doarea () and void show (). 

The main function and algorithm need not be written.

1 Answer

+1 vote
by (49.8k points)
selected by
 
Best answer

import java.util.*; 

class Perimeter 

protected double a,b; 

Perimeter(double aa, double bb) 

a=aa; 

b=bb; 

double Calculate() 

return (2*(a+b)); } 

void show()

System.out.print("\n Length = " + a); 

System.out.print("\n Breadth = " + b); 

System.out.print("\n Perimeter =" + Calculate()); 

importjava.util.*; 

class Area extends Perimeter 

{

double h; 

double area; 

Area(double aa, double bb, double cc) 

{ super(aa, bb); 

h=cc; } 

void doarea() 

area=super.b*h; 

} void show() 

{ super, show(); 

System, out.print("\n Height = " + h);

System.out.print("\n Area = " + area); 

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...