EasyJavaScriptTypeScript

Interfaces — implements & extends

TypeScriptInterfacesOOP

Design a small animal hierarchy using interfaces and implements:

1. Define interface Animal with: name: string, sound(): string.
2. Define interface Pet extends Animal adding: owner: string.
3. Implement class Dog implements Pet with:
- name and owner as constructor params.
- sound() returns "Woof!".

Implement solve(name, owner) that creates a Dog and returns { name, owner, sound: dog.sound() }.

Sample tests

Test #1Rex owned by Alice
Input: ["Rex","Alice"]
Output: {"name":"Rex","owner":"Alice","sound":"Woof!"}
Test #2Buddy owned by Bob
Input: ["Buddy","Bob"]
Output: {"name":"Buddy","owner":"Bob","sound":"Woof!"}
Test #3Max owned by Carol
Input: ["Max","Carol"]
Output: {"name":"Max","owner":"Carol","sound":"Woof!"}