ЁЯУв Too many exams? DonтАЩt know which one suits you best? Book Your Free Expert ЁЯСЙ call Now!

  • google app store apple app store
  • тЬЦ

      Question

      Which of the following is an example of inheritance in

      OOP?
      A A class Car has a method start() that is also defined in class Vehicle. Correct Answer Incorrect Answer
      B Class Bird contains a method fly(), which is not related to any other class. Correct Answer Incorrect Answer
      C Class Employee contains attributes name and salary, while class Manager inherits from Employee. Correct Answer Incorrect Answer
      D An object sends a message to another object requesting it to perform an action. Correct Answer Incorrect Answer
      E Class Circle has a method area() that calculates its area. Correct Answer Incorrect Answer

      Solution

      Inheritance is a mechanism in OOP that allows a new class to inherit the properties and methods of an existing class. This promotes code reusability and establishes a natural hierarchy between classes. In the given example, the Manager class inherits attributes such as name and salary from the Employee class, which means it can use or override these attributes while also introducing its own specific functionalities. This relationship facilitates the organization of code and helps to maintain a clear structure in complex systems. Inheritance can be single or multiple and plays a crucial role in the creation of polymorphic behavior. Option A is partially correct in that it indicates method sharing, but it does not illustrate inheritance specifically. Option B is incorrect because it describes a method in a standalone class without inheritance involved. Option D describes message passing, a communication mechanism, but does not relate to inheritance. Option E mentions a method associated with a class, which does not demonstrate inheritance.

      Practice Next
      More Algorithms Questions

      Relevant for Exams:

      ask-question