Question: *****JAVA********* A heterogeneous pair is a pair of two elements where each element can be of a different reference type. Design and implement a generic

*****JAVA*********

A heterogeneous pair is a pair of two elements where each element can be of a different reference type. Design and implement a generic Java class called HetroPair to represent a heterogeneous pair, according to the following requirements.

(1) Include private fields to store the first and second elements of the pair.

(2) Include a public default constructor, with no parameters, that initializes all fields of the class to their default values.

(3) Include a second public constructor that accepts two elements of generic types and sets the first element of the pair to the first parameter and second element of the pair to the second parameter.

(4) Include two public setter methods called setFirst and setSecond. The method setFirst, takes a parameter of type Object and sets the first element of the pair to its parameter. Similarly, setSecond takes a parameter of type Object and sets the second element of the pair to its parameter. Return type of both setter methods is void.

(5) Include two getter methods called getFirst and getSecond. The method getFirst, takes no parameter and returns the first element of the pair. Similarly, getSecond takes no parameter and returns the second element of the pair.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!