Exam 18: Generic Classes

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Which is the purpose of the <E> element in the class declaration below? public class Thing<E> { public Thing() { ...} }

(Multiple Choice)
4.9/5
(41)

Consider the following code snippet: Consider the following code snippet:   Which of the above lines will cause a compile-time error? Which of the above lines will cause a compile-time error?

(Multiple Choice)
4.7/5
(33)

Which of the following statements about using generic programming is NOT correct?

(Multiple Choice)
4.7/5
(40)

Which of the following necessitates the type erasure process? i.The Java virtual machine does not work with generic types II.To maintain backward compatibility to older versions of Java III.Generics do not work with primitives

(Multiple Choice)
4.9/5
(39)

Consider the following code snippet: public static <E extends Measurable> E min(E[] objects) Which of the following represents the result of type erasure on this code?

(Multiple Choice)
4.9/5
(35)

Consider the following code snippet: public class SavingsAccount extends BankAccount { ...} public class CheckingAccount extends BankAccount { ...} ... SavingsAccount[] savingsAccounts = new SavingsAccount[100]; //Line 1 BankAccount[] bankAccounts = savingsAccounts; //Line 2 BankAccount myAccount = new CheckingAccount(); //Line 3 bankAccounts[0] = myAccount; //Line 4 Which of the following statements regarding this code is correct?

(Multiple Choice)
4.8/5
(47)

Given an object myObject, which of the following represents the correct code to make a new instance of an object having the same class, assuming that the class has a constructor with no arguments?

(Multiple Choice)
4.9/5
(40)

Suppose a generic method accepts a generic unconstrained argument p.What restrictions are placed on p by the compiler?

(Multiple Choice)
4.8/5
(43)

Which of the following headers for a generic method myMethod allows the actionPerformed method from the ActionListener class to be called? i.public static <E extends ActionListener> E myMethod(E e) II.public static <E implements ActionListener> E myMethod(E e) III.public <E extends ActionListener> E myMethod(E e)

(Multiple Choice)
4.9/5
(24)

Consider the following code snippet: public static void reverse(List <? super E> list) { ...} Which of the following statements about this code is correct?

(Multiple Choice)
4.8/5
(42)

Consider the following code snippet: public class Box<E> { private E data; public Box() { ...} } Which of the following choices is a specific type of the generic Box class?

(Multiple Choice)
4.9/5
(31)

What is the best technique for overcoming the restriction for the use of primitives, such as int, in generic classes and methods?

(Multiple Choice)
4.8/5
(30)

Which of the following satisfies the wildcard ? extends Component?

(Multiple Choice)
4.8/5
(37)

Erasure of types limits Java code somewhat with generics.Which of the following are limitations of generic code? i.cannot instantiate a type variable II.cannot return a type variable III.cannot pass a type variable

(Multiple Choice)
4.8/5
(39)

Consider the following code snippet: public class Box<E> { private E data; public Box(){ ...} public void insert(E value) { ...} public E getData(){ ...} } What will result from executing the following code? Box<String> box = new Box<>(); ... box.insert("blue Box"); String b = (Object) box.getData();

(Multiple Choice)
4.8/5
(36)
Showing 61 - 75 of 75
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)