Quiz: Classes and Generics
Test your understanding of TypeScript classes, inheritance, and generics in real-world design scenarios.
We'll cover the following...
We'll cover the following...
1
What is the result of attempting to compile and run the following code in strict mode?
class Tracker {
private time: number;
logTime(): number {
return this.time;
}
}
const t = new Tracker();
console.log(t.logTime());
A)
It compiles successfully but returns undefined at runtime.
B)
It compiles because private fields don’t require initialization.
C)
It fails to compile because time
isn’t initialized anywhere.
D)
It compiles, but only if the method is never called.
Question 1 of 50 attempted
...