Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question F The List method add() depends on the specific representation (instanc

ID: 3855017 • Letter: Q

Question

Question F

The List method add() depends on the specific representation (instance variables and structure) of each particular list implementation. Where does it make the most sense for the add() method to be implemented?

In a concrete super class, like Object

In a concrete class, like ArrayList or LinkedList

In an abstract class, like AbstractList or AbstractCollection

In an interface, like List or Collection

Question I

Which of the following statements is correct about inheritance and interfaces?

A class can extend at most one class and can implement multiple interfaces.

A class can extend multiple classes and can implement at most one interface.

A class can extend multiple classes and can implement multiple interfaces.

A class can extend at most one class and can implement at most one interface.

Question J

Which of the following is true about interface types and abstract classes?

An interface type cannot have constants whereas an abstract class can.

An interface can provide method implementation whereas an abstract class cannot.

An interface type cannot have instance variables whereas an abstract class can.

An interface type cannot be instantiated whereas an abstract class can.

Question K

Which of the following statements about an interface is true?

An interface has neither methods nor instance variables.

An interface has methods but no instance variables.

An interface has methods and instance variables.

An interface has both public and private methods.

Question L

Using the given definition of the Measurable interface:

public interface Measurable
{
    double getMeasure();
}

Consider the following code snippet, assuming that BankAccount has a getBalance() method and implements the Measurable interface by providing an implementation for the getMeasure method:

Measurable m = new BankAccount();
System.out.println(m.getBalance());

Which of the following statements is true?

The code does not compile because you cannot assign a BankAccount object to a variable of type Measurable.

The code compiles but generates an exception at run time because a Measurable object reference does not have a getBalance method.

The code does not compile because a variable of type Measurable does not have a getBalance method.

The code executes, displaying the balance of the bank account.

In a concrete super class, like Object

In a concrete class, like ArrayList or LinkedList

Explanation / Answer

F. add method is an abstract method in List interface. So, it makes sense to implement the method in the actual concrete classes like ArrayList or LinkedList. They can have their own implementations for add method

I. A class can extend atmost one class and can implement multiple interfaces.

J. All the variables in an interface are public static final by default. So, an interface can have constants. An interface can not provide method implementation, but abstract class can. Both interfaces and abstract classes can't be instantiated.
Ans is C : An interface can not have instance variables. Because all the variables are public static final by default. Whereas an abstract class can have instance variables

K. Ans is B. An interface has methods but no instance variables. But all the methods in the interface are abstract.

L. Ans is C. Code doesn't compile because a variable of type Measurable doesn't have a getBalance method

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote