PHP Overriding


Method Overriding

Method overriding achieved by the same method and the same parameter in base class as well as in derived class. Method overriding used only in different classes.

Syntax:

 class A {  
	public:  
		void show(){
         //body of the function. 
        }    
}
class B {  
	public:  
		void show(){
         //body of the function. 
        }    
} 
php function overriding

Example:

<?php
// Base class
class A {
    public function showdata() {
        echo "Base class\n";
    }
}

// Derived class
class B extends A {
    public function showdata() {
        echo "Derived class\n";
    }
}

// Main execution
$b = new B();
$b->showdata(); // Calls overridden method in class B
?>



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.