AllInfoHub Logo

AllInfoHub – MCQ Practice

Inheritance and Polymorphism – Multiple Choice Questions (MCQs)

  1. 37. What is the output of the following code? `interface MyInterface {} class MyClass implements MyInterface {} public class InstanceOfInterfaceDemo { public static void main(String[] args) { MyClass obj = new MyClass(); System.out.println(obj instanceof MyInterface); } }`

    • A. TRUE
    • B. FALSE
    • C. Error
    • D. None
  2. 38. What is the significance of the `Object` class in Java's inheritance hierarchy?

    • A. It is the superclass of all classes
    • B. It is the only class that cannot be subclassed
    • C. It represents primitive data types
    • D. It is an interface
  3. 39. Which methods are inherited by all Java objects from the `Object` class?

    • A. `toString()`
    • B. `equals()`
    • C. `hashCode()`
    • D. `clone()`
  4. 40. What is the purpose of the `toString()` method inherited from the `Object` class?

    • A. To compare two objects
    • B. To get the hash code of an object
    • C. To return a string representation of the object
    • D. To create a copy of the object
  5. 41. What is the purpose of the `equals()` method inherited from the `Object` class?

    • A. To return a string representation of the object
    • B. To compare two objects for equality
    • C. To get the hash code of an object
    • D. To create a copy of the object
  6. 42. What is the purpose of the `hashCode()` method inherited from the `Object` class?

    • A. To return a string representation of the object
    • B. To compare two objects for equality
    • C. To return a hash code value for the object
    • D. To get the class of the object
  7. 43. What is the purpose of the `clone()` method inherited from the `Object` class?

    • A. To return a string representation of the object
    • B. To compare two objects for equality
    • C. To get the hash code of an object
    • D. To create a shallow copy of the object