Filter by the role you are applying for, open a question, and practise explaining the answer out loud. Mark it practised when you can.
Why they ask this: Asked in almost every fresher interview in Nepal; a clear answer with examples stands out.
Answer
private properties, public methods).PaymentGateway interface with a charge() method.class Admin extends User).interface PaymentGateway
{
public function charge(int $amountInPaisa): bool;
}
final
Why they ask this: Tests whether you can design flexible code rather than only reciting definitions.
Answer
Why they ask this: Mid-level and good junior candidates are expected to know how to keep code maintainable.
Answer
Why they ask this: Checks design maturity; deep inheritance trees are a common source of rigid code.
Answer
| Interface | Abstract class | |
|---|---|---|
| Contains | method signatures (and constants) | abstract and implemented methods, plus properties |
| A class can use | many interfaces | only one parent class (in PHP, Java and Dart) |
| Constructor and state | no | yes |
| Meaning | "can do" (a capability) | "is a" (a shared base) |
Cacheable, PaymentGateway.Report base class with an abstract rows() method.In PHP you can combine both, and use traits to share code horizontally. Dart has no interface keyword in older versions: every class can be implemented with implements, and Dart 3 adds interface class.
KhaltiGateway class instead of adding another if to existing code.Do not just recite the list: give one real example from your own project of a principle you applied, or one you broke and later fixed.
// Inheritance: every new notification channel needs a new subclass
class SmsOrderNotifier extends OrderNotifier { /* ... */ }
// Composition: inject the channel
final class OrderNotifier
{
public function __construct(private NotificationChannel $channel) {}
public function notify(Order $order): void
{
$this->channel->send($order->customer, "Order #{$order->id} confirmed");
}
}Inheritance is still fine for a true, stable "is a" relationship with shared behaviour. Flutter is a good example of composition: UIs are built by nesting small widgets rather than extending big ones.