practical Object-Oriented PHP (OOP) practice questions

🟢 Beginner Level

1. Class & Object

Create a class Car with properties:

  • brand
  • model

Create a method showDetails() to print car details.


2. Constructor

Create a class Student with:

  • name
  • age

Initialize values using a constructor and display them.


3. Method Calling

Create a class Calculator with methods:

  • add()
  • subtract()
  • multiply()
  • divide()

🟡 Intermediate Level

4. Inheritance

Create a parent class Animal with method makeSound()
Create child classes:

  • Dog → “Bark”
  • Cat → “Meow”

5. Encapsulation

Create a class BankAccount:

  • private property: balance
  • methods: deposit(), withdraw(), getBalance()

6. Static Methods & Properties

Create a class Counter:

  • static property $count
  • static method increment()

7. Constants

Create a class MathConstants:

  • define PI
  • use it in a method to calculate area of a circle

🔵 Advanced Level

8. Abstract Class

Create abstract class Shape:

  • abstract method area()

Child classes:

  • Circle
  • Rectangle

9. Interface

Create interface Payment:

  • method pay()

Classes:

  • CreditCard
  • PayPal

10. Polymorphism

Create multiple classes with same method draw():

  • Circle
  • Square
  • Triangle

11. Magic Methods

Create a class User:

  • use __construct()
  • use __destruct()
  • use __toString()

12. File Handling with OOP

Create a class FileManager:

  • read file
  • write file

🔴 Real-World Practice (Important 🚀)

13. Mini Project – User Login System

  • Class User
  • Register user
  • Login user
  • Validate password

14. Shopping Cart System

  • Product class
  • Cart class
  • Add/remove items
  • Calculate total

15. Blog System (OOP)

  • Post class
  • Comment class
  • User class

💡 Bonus Interview Questions

  • What is OOP?
  • Difference between Interface & Abstract Class?
  • What is encapsulation?
  • What is polymorphism?
  • What is late static binding?