Object-Oriented Programming Inheritance

CaptivatingKrypton avatar
CaptivatingKrypton
·
·
Download

Start Quiz

Study Flashcards

10 Questions

Inherit______nce is ______ concept of ______ccessing properties & methods of one cl______ss from ______nother cl______ss.

a

To define a (child) class that inherits (derives) from another (parent) class, you use the ______ keyword.

extends

The parent class is also called a ______ class or super class.

base

One of the most important feature of inheritance in OOP is that it facilitates ______ reusability.

code

Inheritance in PHP is of 3 types: single, multiple & ______ inheritance.

multi-level

What is the primary purpose of method overriding in OOP?

To allow a child class to provide a specific implementation of a method already provided by its parent class

What happens when an object of the parent class invokes a method that has been overridden by a child class?

The overridden method in the parent class is executed

What determines which method (overridden or overriding) is called by PHP?

The object used to invoke the method

What is the term for the method in the parent class that is overridden by a child class?

Overridden method

What happens when an object of the child class invokes a method that has been overridden?

The overriding method in the child class is executed

Study Notes

Inheritance in OOP

  • Inheritance is a concept that allows one class to access properties and methods of another class.

Defining Inheritance

  • A child class inherits (derives) from a parent class using the extends keyword.
  • This enables the child class to inherit all public and protected properties and methods from the parent class.

Characteristics of Inheritance

  • A child class can have its own properties and methods in addition to the inherited ones.
  • The parent class is also known as a base class or super class.
  • The child class is also known as a derived class or a subclass.

Benefits of Inheritance

  • Inheritance facilitates code reusability, saving time and effort while promoting clean code.

Types of Inheritance in PHP

  • There are three types of inheritance in PHP: single, multiple, and multi-level inheritance.

Importance of Inheritance

  • Understanding inheritance is crucial for grasping the fundamental principles of object-oriented programming and its real-world applications.

Method Overriding in OOP

  • Method overriding allows a child class to provide a specific implementation of a method already provided by its parent class.
  • The parent class method is called the overridden method, while the child class method is known as the overriding method.
  • The overriding method's code replaces the code in the overridden method.
  • PHP determines which method to call (overridden or overriding) based on the object used to invoke the method.

Method Invocation

  • If an object of the parent class invokes the method, PHP executes the overridden method.
  • If an object of the child class invokes the method, PHP executes the overriding method.

This quiz is about inheritance in object-oriented programming, where a child class inherits properties and methods from a parent class.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Use Quizgecko on...
Browser
Browser