Write a generic class called Trio that has one type parameter. It contains an ar
ID: 3613392 • Letter: W
Question
Write a generic class called Trio that has one type parameter. It contains an array of three elements of the type parameter's type. It contains three methods, first() and second(), and third(), that return one of the three items respectively. Include a main method in the class which creates a Trio object with a String type. The object should be created with three strings: "abc", "def", "ghi". Use the first(), second(), and third() methods to get each string from the Trio object and print itExplanation / Answer
publicclass Trio { private AnyType[]array; publicTrio(AnyType a1, AnyType a2, AnyType a3) { array=(AnyType[])(newObject[3]); array[0]=a1; array[1]=a2; array[2]=a3; } public AnyTypefirst() { return array[0]; } public AnyTypesecond() { return array[1]; } public AnyTypethird() { return array[2]; } } // code in main Trio test = new Trio("abc","def", "ghi"); System.out.println(test.first()); System.out.println(test.second()); System.out.println(test.third());Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.