Practical - 7 IWD

 

Aim: Demonstrate Single Inheritance in PHP

Program

<?php // Parent class class Animal { public function sound() { echo "Animals make sounds."; } } // Child class (single inheritance) class Dog extends Animal { public function sound() { echo "Dog barks."; } } // Object creation $dog = new Dog(); // Calling method $dog->sound(); ?>


  • Animal is the parent (base) class.

  • Dog is the child (derived) class.

  • Dog inherits the Animal class using extends.

  • This demonstrates single inheritance (one parent → one child).

Comments

Popular posts from this blog

Unit I - Introduction to PHP

Practical - 1 IWD

Practical - 10 IWD