Answer & Solution
class Dog extends Animal { }In PHP, the extends keyword is used to implement inheritance, where the child class (Dog) inherits from the parent class (Animal).
class Dog extends Animal { }What does the protected access modifier mean in PHP?
A). Access to all
B). Access to parent class
C). Access to subclass
D). Restricted access
What is the purpose of the interface keyword in PHP?
A). Finalize a class
B). Define a contract
C). Abstract a class
D). Create a subclass
Which access modifier in PHP restricts access to class members?
A). public
B). protected
C). private
D). access
In PHP, what is the purpose of the abstract keyword?
A). To specify a class as final
B). To specify a class as abstract
C). To prevent a class from being instantiated
D). To mark a method as deprecated
In PHP, what is the default visibility of class members?
A). Public
B). Protected
C). Private
D). Global
Which of the following statements is true about polymorphism?
A). It allows a class to inherit from multiple classes
B). It allows a class to have multiple constructors
C). It allows a method to have multiple implementations
D). It allows a class to override parent class methods
How is polymorphism achieved in PHP?
A). Method overriding
B). Method overloading
C). Method inheritance
D). Method encapsulation
Which keyword is used to access static properties or methods in PHP?
A). this
B). parent
C). self
D). static
What is the main purpose of encapsulation?
A). To make classes more readable
B). To hide implementation details
C). To increase code complexity
D). To prevent inheritance
Which of the following is an advantage of inheritance in PHP?
A). Increases code reusability
B). Decreases code maintainability
C). Adds complexity to the code
D). Makes code less modular