0

Abstract Classes and Implementing Interfaces

Description: Abstract Classes and Implementing Interfaces
Number of Questions: 15
Created by:
Tags: Abstract Classes and Implementing Interfaces Java/Oracle /C/C++ Java Inheritance and Constructor
Attempted 0/15 Correct 0 Score 0

Which of the following statements regarding 'finally' block in Java is false?

  1. Before the termination of the program, JVM executes the 'finally' block (if any).

  2. The 'finally' block can be used for writing the cleanup code.

  3. The 'finally' block must be followed by try or catch block.

  4. There can be multiple 'finally' blocks for a try block.

  5. The 'finally' block is not executed if the program exists.


Correct Option: D
Explanation:

This is a false statement. There can only be one finally block for each try block. Since the statement is false about 'finally' block in Java, it is the correct alternative.

The class String is defined in the package ___________.

  1. java.awt

  2. java.lang

  3. java.math

  4. java.net


Correct Option: B
Explanation:

The class String is defined in the package java.lang.

Which of the following package methods returns the name of the invoking package?

  1. String getName()

  2. String getImplementationTitle()

  3. String getImplementationVersion()

  4. String getImplementationVendor()

  5. String getSpecificationTitle()


Correct Option: A
Explanation:

This method returns the name of the invoking package.

Which of the following interfaces enables you to work with a group of objects?

  1. Collection

  2. List

  3. Set

  4. SortedSet

  5. SecurityManager


Correct Option: A
Explanation:

This interface enables you to work with a group of objects.

An abstract class cannot be _____________ in Java.

  1. declared

  2. defined

  3. instantiated

  4. inherited


Correct Option: C
Explanation:

An abstract class cannot be instantiated in Java that is the instance of abstract class cannot be created.

The method within the abstract class must be _________.

  1. static

  2. final

  3. constant

  4. abstract


Correct Option: D
Explanation:

The method within the abstract class must be abstract, which should also be defined in another class.

Which of the following is not an interface of Java Collection Framework?

  1. Set

  2. List

  3. Queue

  4. HashSet


Correct Option: D
Explanation:

A HashSet is a class and not an interface. The interface Set is implemented in a HashSet class.

Which of the following classes offers all the benefits of an array with the properties of the List interface?

  1. LinkedList

  2. ArrayList

  3. TreeSet

  4. HashMap


Correct Option: B
Explanation:

The class ArrayList offers all the benefits of an array with the properties of the List interface.

Which of the following classes is not implemented the interface Map?

  1. HashMap

  2. TreeMap

  3. LinkedHashMap

  4. ArrayMap


Correct Option: D
Explanation:

There is no such class with the name ArrayMap. The Map interface is implemented in class HashMap, class TreeMap and class LinkedHashMap.

Which of the following is false regarding interface in Java?

  1. An interface can have only abstract methods.

  2. Constructors cannot be present in an interface.

  3. An interface can have instance variables.

  4. An interface cannot have static methods.

  5. A class can implement multiple interfaces.


Correct Option: C
Explanation:

This is a false statement. An interface cannot have instance variables.

You want a subclass in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?

  1. public

  2. private

  3. protected

  4. transient

  5. default


Correct Option: C
Explanation:

Access modifiers dictate which classes, not which instances, may access features.Methods and variables are collectively known as members. Method and variable members are given access control in exactly the same way.

Which of the following interfaces in java.beans package allows designers to change and display property value?

  1. DesignMode

  2. PropertyChangeListener

  3. PropertyEditor

  4. Visibility

  5. BeanInfo


Correct Option: C
Explanation:

This interface in java.beans package allows designers to change and display property value.

Which of the following accessibility modes in Java does not allow a method to access the data members from the non-subclass of the same package?

  1. Protected

  2. Public

  3. Private

  4. No modifier

  5. Virtual


Correct Option: C
Explanation:

This accessibility mode in Java does not allow a method to access the data members from the non-subclass of the same package.

In Java _________ is a interface.

  1. Map

  2. HashMap

  3. HashTable

  4. Table

  5. Arrays


Correct Option: A
Explanation:

Map is a data structure which is used to put data as key value pair for quick retrieval. So it is an interface.

Which of the following methods of Iterator class throws NoSuchElementException, if the next element does not exist?

  1. hasNext()

  2. next()

  3. remove()

  4. add()

  5. nextIndex()


Correct Option: B
Explanation:

This method of Iterator class throws NoSuchElementException, if there is not a next element.

- Hide questions