Recall & Review
beginner
What is polymorphism in TypeScript?
Polymorphism means one interface can represent different types of objects. It lets you use the same method or property name for different behaviors.
Click to reveal answer
beginner
How do interfaces help achieve polymorphism in TypeScript?
Interfaces define a contract with methods or properties. Different classes can implement the same interface but behave differently, enabling polymorphism.
Click to reveal answer
beginner
Example: What does this interface represent?
interface Animal { speak(): void; }It represents any animal that can speak. Different animals can implement speak() in their own way.
Click to reveal answer
intermediate
What happens when you call a method on an interface type variable?
The actual method of the object assigned to that variable runs. This is polymorphism: same call, different results.
Click to reveal answer
beginner
Why is polymorphism useful in programming?
It lets you write flexible and reusable code. You can work with different objects through the same interface without knowing their exact types.
Click to reveal answer
What does polymorphism allow you to do with interfaces in TypeScript?
✗ Incorrect
Polymorphism lets different classes implement the same interface but behave differently.
Which keyword is used to make a class follow an interface in TypeScript?
✗ Incorrect
The 'implements' keyword tells TypeScript that a class follows an interface.
If two classes implement the same interface, what can you do with their objects?
✗ Incorrect
Objects of classes implementing the same interface can be used interchangeably where that interface is expected.
What will happen if a class does not implement all methods of an interface?
✗ Incorrect
TypeScript requires all interface methods to be implemented, otherwise it shows an error.
Which of these is an example of polymorphism through interfaces?
✗ Incorrect
Polymorphism means different classes implement the same interface method in their own way.
Explain how polymorphism works with interfaces in TypeScript.
Think about how one interface can represent many types.
You got /4 concepts.
Describe a real-life example that shows polymorphism through interfaces.
Imagine animals making sounds differently but all can speak.
You got /3 concepts.