1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
seraphim [82]
3 years ago
9

4. Write an interface ObjectWithTwoParameters which has a method specification: double area (double d1, double d2) which returns

the area of a particular object. Write three classes RectangleClass, TriangleClass, and CylinderClass which implement the interface you created. Also, write a demo class which creates objects of RectangleClass, TriangleClass, and CylinderClass and call the corresponding methods
Computers and Technology
1 answer:
il63 [147K]3 years ago
8 0

Answer:

The java program for the given scenario is as follows.

import java.util.*;

//interface with method area

interface ObjectWithTwoParameters

{

double area (double d1, double d2);

}

class RectangleClass implements ObjectWithTwoParameters

{

//overriding area()

public double area (double d1, double d2)

{

return d1*d2;

}

}

class TriangleClass implements ObjectWithTwoParameters

{

//overriding area()

public double area (double d1, double d2)

{

return (d1*d2)/2;

}  

}

class CylinderClass implements ObjectWithTwoParameters

{

public double area (double d1, double d2)

{

return ( 2*3.14*d1*d1 + d2*(2*3.14*d1) );

}

}

public class Test

{

public static void main(String[] args)

{

//area displayed for all three shapes

ObjectWithTwoParameters r = new RectangleClass();

double arear = r.area(2, 3);

System.out.println("Area of rectangle: "+arear);

ObjectWithTwoParameters t = new TriangleClass();

double areat = t.area(4,5);

System.out.println("Area of triangle: "+areat);

ObjectWithTwoParameters c = new CylinderClass();

double areac = c.area(6,7);

System.out.println("Area of cylinder: "+areac);

}

}

OUTPUT

Area of rectangle: 6.0

Area of triangle: 10.0

Area of cylinder: 489.84

Explanation:

1. The program fulfils all the mentioned requirements.

2. The program contains one interface, ObjectWithTwoParameters, three classes which implement that interface, RectangleClass, TriangleClass and CylinderClass, and one demo class, Test, containing the main method.

3. The method in the interface has no access specifier.

4. The overridden methods in the three classes have public access specifier.

5. No additional variables have been declared.

6. The test class having the main() method is declared public.

7. The area of the rectangle, triangle and the cylinder have been computed as per the respective formulae.

8. The interface is similar to a class which can have only declarations of both, variables and methods. No method can be defined inside an interface.

9. The other classes use the methods of the interface by implementing the interface using the keyword, implements.

10. The object is created using the name of the interface as shown.

ObjectWithTwoParameters r = new RectangleClass();

You might be interested in
When you're working with a word processing document and you press the DEL Key what happens
wariber [46]
<span>The character to the right of the cursor is deleted. </span>
4 0
3 years ago
Read 2 more answers
Select the correct answer.
Sladkaya [172]

Answer:

B

Explanation:

hes not presenting, word processing or making spreadsheets and multimedia software can be used to make music

5 0
3 years ago
Read 2 more answers
The movie polar express was critically acclaimed due to the unbelievably lifelike movements of Tom Hanks character
Fed [463]
I think it is greyhound
6 0
2 years ago
when an overridden method is called from within a subclass, it will always refer to the version of that method defined by the (a
bija089 [108]

Option b is correct. When an overridden method is called from within a subclass, it will always refer to the version of that method defined by the subclass.

Subclasses are classes that can be created by adding new functionality to a parent class, such as new object variables or new methods. In terms of automata theory, a subclass expands the state transition table with new rows and states. However, by overriding (changing) existing functionality, the majority of OO programming languages also enable us to derive subclasses from parent classes. When implementing a class, all that is required to be specified is the new or updated functionality thanks to inheritance mechanisms between parent class and subclass.

Lines connected through a circle connect the subclasses HourlyEmployee and SalaryEmployee to the superclass Employee. The circled letter "d" stands for disjointness, which demands that the specification's subclasses be distinct. As a result, an entity can belong to only one of the specification's subclasses. An individual employee can only be paid either hourly wages or a salary; they cannot be paid both. The open sides of the inheritance (arch) symbols face the superclass.

To know more about subclass click on the link:

brainly.com/question/13790787

#SPJ4

6 0
1 year ago
The coordinates for the section element need not be defined as long as its position is set to
scoray [572]
<h2><u>Answer:</u></h2>

relative.

<h2><u>Explanation:</u></h2>

The coordinates for the section element need not be defined as long as its position is set to relative.

If the position is set as relative, then it will have no effect on the positioning attributes, it will consider as static position. If positioning is mentioned explicitly like top: 20px; then it will position 10 pixels down from where it is located. An ability for positional shifts is extremely helpful.

Two things happen when an element is set as relative, one is it introduces the ability to use z-index on that element, second is it limits the scope of absolutely positioned child elements.  

5 0
2 years ago
Other questions:
  • User accounts will be locked out after authentication is attempted
    7·1 answer
  • Some people are unable to arrange six matches to form four equilateral triangles because they fail to consider a three - dimensi
    6·1 answer
  • Given the following class import java.util.ArrayList; public class RectangleTester { public static void main(String[ ] args) { A
    7·1 answer
  • George and Miguel want to know more about their local and online competitors and about the retail industry. What is the best way
    9·1 answer
  • Declare a prototype for a function called isPrime that returns true or false and expects a single parameter named number of type
    14·1 answer
  • Which two encryption protocols might be used to provide secure transmissions for browser and web server communications?
    14·1 answer
  • what is the total resistance of a series circuit with four resistors in series of 12 16 20 and 24 ohms​
    14·1 answer
  • Kim is creating a PowerPoint
    13·1 answer
  • _____ refers to the busiest calling hour of the day, week, month or year. And _____ refers to the average length of time the sub
    14·1 answer
  • Which backup requires a small amount of space and is considered to have an involved restoration process?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!