Inheritance - Practice Quiz

11. What is inheritance in Java?

  • A way to create objects of a class.
  • A mechanism to hide the implementation details of a class.
  • A process of creating a new class by inheriting properties and methods from an existing class.
  • A technique to access variables and methods of an object.

12. What is multiple inheritance in Java?

  • The ability of a class to inherit from multiple classes at the same time.
  • The ability of a class to inherit from a single class only.
  • The ability of a class to inherit from any number of classes.
  • The ability of a class to inherit from abstract classes only.

13. What is polymorphism in Java?

  • The ability of a class to have multiple constructors.
  • The ability of a class to have multiple methods with the same name but different parameters.
  • The ability of objects of different classes to respond to the same method call.
  • The ability of a class to inherit properties and methods from another class.

14. What is dynamic method dispatch or runtime polymorphism in Java?

  • The ability of a class to have multiple constructors.
  • The ability of a class to have multiple methods with the same name but different parameters.
  • The ability of objects of different classes to respond to the same method call.
  • The ability of a method in a subclass to override a method in its superclass and get invoked at runtime based on the actual object type.

15. What is the main difference between inheritance in C++ and Java?

  • C++ supports multiple inheritance, while Java does not.
  • Java supports multiple inheritance, while C++ does not.
  • C++ supports polymorphism, while Java does not.
  • Java supports polymorphism, while C++ does not.

Overloading and Overriding - Practice Quiz

16. What is method overloading in Java?

  • The ability of a class to have multiple methods with the same name but different return types.
  • The ability of a class to have multiple methods with the same name and same parameter list.
  • The ability of a class to override methods from its superclass.
  • The ability of a class to have multiple methods with the same name but different parameter lists.

17. Which of the following is a way to achieve method overloading in Java?

  • Using the same method name and the same parameter list in multiple classes in a hierarchy.
  • Using the same method name and the same parameter list in a single class.
  • Using the same method name and the same return type in a single class.
  • Using the same method name but different parameter lists in a single class.

18. What is method overriding in Java?

  • The ability to have multiple methods with the same name in a single class.
  • The ability to inherit methods from multiple classes at the same time.
  • The ability to create new methods in a subclass that have the same name as methods in the superclass.
  • The ability to provide a new implementation of a method in a subclass that overrides the implementation in the superclass.

19. What is the difference between method overloading and method overriding in Java?

  • Method overloading is based on the same method name but different parameter lists in a single class, while method overriding is based on the same method name and the same parameter list in multiple classes in a hierarchy.
  • Method overloading is based on the same method name but different parameter lists in a single class, while method overriding is based on the same method name and the same parameter list in a single class.
  • Method overloading is the ability to provide a new implementation of a method in a subclass that overrides the implementation in the superclass, while method overriding is the ability to have multiple methods with the same name in a single class.
  • Method overloading is based on the same method name but different parameter lists in a single class, while method overriding is the ability to provide a new implementation of a method in a subclass that overrides the implementation in the superclass.

20. What are the different ways of achieving method overloading in Java?

  • By providing multiple methods with the same name and same parameter list in a single class.
  • By providing multiple methods with the same name but different return types in a single class.
  • By providing multiple methods with the same name but different parameter lists in a single class.
  • By providing multiple methods with the same name and same parameter list in different classes of a hierarchy.

Leave a Reply