PHP - Inheritance and PolymorphismWhat happens when a child class overrides a method from its parent class in PHP?AThe parent class method is called instead of the child's method.BThe child class provides its own version of the method, replacing the parent's version.CBoth parent and child methods run automatically in sequence.DThe method becomes private and cannot be accessed.Check Answer
Step-by-Step SolutionSolution:Step 1: Understand method overriding conceptWhen a child class defines a method with the same name as in the parent, it replaces the parent's method.Step 2: Effect of overriding in PHPThe child's method is called when invoked on the child object, hiding the parent's version.Final Answer:The child class provides its own version of the method, replacing the parent's version. -> Option BQuick Check:Method overriding = Child method replaces parent method [OK]Quick Trick: Child method replaces parent method with same name [OK]Common Mistakes:Thinking both methods run automaticallyAssuming parent method is called insteadConfusing overriding with overloading
Master "Inheritance and Polymorphism" in PHP9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PHP Quizzes Classes and Objects - Methods and $this keyword - Quiz 15hard Classes and Objects - Class declaration syntax - Quiz 4medium Classes and Objects - Destructor method - Quiz 6medium Classes and Objects - Constants in classes - Quiz 7medium File Handling - File existence and info checks - Quiz 13medium Inheritance and Polymorphism - Constructor inheritance - Quiz 11easy Inheritance and Polymorphism - Type hinting with parent classes - Quiz 12easy Interfaces and Traits - Interface vs abstract class vs trait - Quiz 2easy Sessions and Cookies - Starting and using sessions - Quiz 6medium String Functions - Trim functions - Quiz 4medium