TypeScript | Generics in TypeScript | Question4

Last Updated :
Discuss
Comments

Which of the following defines a generic class?

TypeScript
class Box<T> {
    private content: T;
    constructor(content: T) {
        this.content = content;
    }
    getContent(): T {
        return this.content;
    }
}


Box is a generic class where T can be replaced with a specific type.

T must always be a string in this class.

T is a built-in generic type.

The class is invalid because it uses <T>.

Share your thoughts in the comments