Abstract Classes and Implementing Interfaces

Test your knowledge of Java abstract classes and interfaces, including collection framework abstract classes (AbstractList, AbstractSet), common interfaces (Runnable, Map, Map.Entry), and practical implementation patterns.

14 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

______________ collection class extends the AbstractList for a collection that uses sequential access, rather than the random access of its elements.

  1. Abstract
  2. AbstractSequentialList
  3. AbstractList
  4. LinkedList
  5. AbstractSet
Question 2 Multiple Choice (Single Answer)

Which of the following classes implements a dynamic array by extending the AbstractList?

  1. TreeSet
  2. ArrayList
  3. HashSet
  4. AbstractList
  5. None of these
Question 3 Multiple Choice (Single Answer)

When we implement the Runnable interface in a class, then we must define _____ method.

  1. init()
  2. main()
  3. start()
  4. run()
  5. none of the above
Question 4 Multiple Choice (Single Answer)

Which of the following interfaces in Java servlets indicates that the servlet is thread safe?

  1. ServletRequest
  2. ServletResponse
  3. SingleThreadModel
  4. Servlet
  5. ServletConfig
Question 5 Multiple Choice (Single Answer)

Which of the following methods in Map.Entry interface in Java returns the value for the map entry?

  1. getKey()
  2. getValue()
  3. hashCode()
  4. none of these
Question 6 Multiple Choice (Single Answer)

Which of the following methods, declared by Map interface, returns a Set that contains the entries in the Map interface?

  1. containsKey()
  2. containsValue()
  3. entrySet()
  4. none of these
Question 7 Multiple Choice (Single Answer)

In Java, which of the following is implemented by extending AbstractSequentialList class?

  1. AbstractCollection
  2. AbstractList
  3. LinkedList
  4. None of these
Question 8 Multiple Choice (Single Answer)

Which of the following statements are true?

  1. The Iterator interface declares only three methods: hasNext, next and remove.
  2. The ListIterator interface extends both the List and Iterator interfaces.
  3. The ListIterator interface provides forward and backward iteration capabilities.
  4. The ListIterator interface provides the ability to modify the List during iteration.
  5. The ListIterator interface provides the ability to determine its position in the List.
  1. 2, 3, 4 and 5
  2. 1, 3, 4 and 5
  3. 3, 4 and 5
  4. 1, 2 and 3
Question 9 Multiple Choice (Single Answer)

Which of the following in collection classes in Java implements a set stored in a tree and also extends AbstractSet class?

  1. ArrayList
  2. TreeSet
  3. AbstractSet
  4. HashSet
Question 10 Multiple Choice (Single Answer)

Which of the following methods in ListIterator class returns true if there is a next element otherwise returns false?

  1. add()
  2. hasPrevious()
  3. next()
  4. hasNext()
Question 11 Multiple Choice (Single Answer)

What will be the output of the program?

interface Count {
 short counter = 0;
 void countUp();
}
public class TestCount implements Count {
 public static void main(String[] args) {
  TestCount t = new TestCount();
  t.countUp();
 }
 public void countUp() {
  for (int x = 6; x > counter; x--, ++counter) /* Line 10 */ {
   System.out.print(" " + counter);
  }
 }
}
  1. 0 1 2
  2. 1 2 3
  3. 0 1 2 3
  4. Compilation error
Question 12 Multiple Choice (Single Answer)

What will be the output of the program?

public abstract class AbstractTest {
 public int getNum() {
  return 45;
 }
 public abstract class Bar {
  public int getNum() {
   return 38;
  }
 }
 public static void main(String[] args) {
  AbstractTest t = new AbstractTest() {
   public int getNum() {
    return 22;
   }
  };
  AbstractTest.Bar f = t.new Bar() {
   public int getNum() {
    return 57;
   }
  };
  System.out.println(f.getNum() + +t.getNum());
 }
}
  1. 57 22
  2. 45 38
  3. 45 57
  4. An exception occurs at runtime
Question 13 Multiple Choice (Single Answer)

___________ interface allows a designer to provide a graphical user interface through which bean may be configured.

  1. Customizer
  2. AppletInitializer
  3. BeanInfo
  4. DesignMode
  5. PropertyEditor
Question 14 Multiple Choice (Single Answer)

Which of the following interfaces in Java Beans API allows a designer to specify information about the properties, events and methods of a bean?

  1. Customizer
  2. Visibility
  3. BeanInfo
  4. DesignMode
  5. None of these