In the following code given the class definitions from the l

In the following code, given the class definitions from the lectures, which methods would be able to be used in the blank below? You do not need to worry about what the code would do, just whether it would compile or not. public class MyClass {ArrayList dogs = new ArrayList();//...more code here... public void doSomething() {for(T dog: dogs) {dog. ()}}} bark() available mush() not available toString() track()

Solution

Code: The above code compiled if Dog class already exists and imports the util package for ArrayList.

import java.util.ArrayList;

public class MyClass<T extends Dog> {
ArrayList<T> dogs=new ArrayList<T>();
public void doSomthing()
{
for(T dog:dogs)
{
dog.toString();
}
}
}

Answer : A.available that means toString() method is available for dog object.

toString() method is default method

 In the following code, given the class definitions from the lectures, which methods would be able to be used in the blank below? You do not need to worry about

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site