Encapsulation in OOP refers to the bundling of data (attributes) and methods (behaviors) that operate on the data into a single unit, called a class. It hides the internal state of an object and only exposes the necessary functionalities through methods.
Inheritance in OOP allows a class (subclass or derived class) to inherit properties and methods from another class (superclass or base class). It promotes code reusability and enables the creation of a hierarchy of classes.
Polymorphism in OOP allows objects of different classes to be treated as objects of a common superclass. It enables flexibility in code design by allowing methods to behave differently based on the object's type.
9.
Which concept allows a method in a subclass to have the same name as a method in its superclass?
Inheritance allows a method in a subclass to have the same name as a method in its superclass. This is known as method overriding, where the subclass provides a specific implementation of the method.
10.
What is the purpose of the __construct() method in PHP?
The __construct() method in PHP is a special method used to initialize object properties or perform any necessary setup when an object is created. It is automatically called when a new object is instantiated.