0
0
Typescriptprogramming~20 mins

Class implementing multiple interfaces in Typescript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Interface Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a class implementing two interfaces
What will be the output of the following TypeScript code?
Typescript
interface A {
  greet(): string;
}

interface B {
  farewell(): string;
}

class C implements A, B {
  greet() {
    return "Hello";
  }
  farewell() {
    return "Goodbye";
  }
}

const obj = new C();
console.log(obj.greet() + ", " + obj.farewell());
A"Goodbye, Hello"
B"Hello, Goodbye"
CTypeError at runtime
DSyntaxError at compile time
Attempts:
2 left
💡 Hint
Check the methods implemented by class C and their return values.
Predict Output
intermediate
1:30remaining
Value of property after implementing multiple interfaces
Given the following code, what is the value of obj.status after execution?
Typescript
interface X {
  status: string;
}

interface Y {
  status: string;
}

class Z implements X, Y {
  status = "active";
}

const obj = new Z();
A"active"
B"inactive"
Cundefined
DCompilation error due to duplicate property
Attempts:
2 left
💡 Hint
Consider how TypeScript handles properties with the same name in multiple interfaces.
🔧 Debug
advanced
2:30remaining
Identify the error in class implementing multiple interfaces
What error will this TypeScript code produce?
Typescript
interface First {
  doSomething(): void;
}

interface Second {
  doSomething(): number;
}

class Test implements First, Second {
  doSomething() {
    return 42;
  }
}
ANo error, code compiles and runs fine.
BSyntax error: Missing return type in method.
CRuntime error: doSomething returns wrong type.
DTypeScript error: Class incorrectly implements interface 'First'. Type 'number' is not assignable to type 'void'.
Attempts:
2 left
💡 Hint
Check the return types of the method in both interfaces and the class.
📝 Syntax
advanced
1:30remaining
Correct syntax for implementing multiple interfaces
Which of the following is the correct syntax for a class implementing interfaces Alpha and Beta in TypeScript?
Aclass MyClass implements Alpha, Beta {}
Bclass MyClass implements (Alpha & Beta) {}
Cclass MyClass implements [Alpha, Beta] {}
Dclass MyClass extends Alpha, Beta {}
Attempts:
2 left
💡 Hint
Remember how TypeScript lists multiple interfaces in the implements clause.
🚀 Application
expert
3:00remaining
Determine the number of methods in a class implementing multiple interfaces
Given these interfaces and class, how many methods does the class FinalClass have?
Typescript
interface One {
  methodA(): void;
  methodB(): void;
}

interface Two {
  methodB(): void;
  methodC(): void;
}

interface Three {
  methodD(): void;
}

class FinalClass implements One, Two, Three {
  methodA() {}
  methodB() {}
  methodC() {}
  methodD() {}
}
A5
B3
C4
D2
Attempts:
2 left
💡 Hint
Count unique method names implemented in the class.