TypeScript Classes and Objects Quiz
A 40-question TypeScript quiz focusing on classes, constructors, access modifiers, readonly fields, methods, inheritance, abstract classes, and object-based typing.
Question 1
What keyword defines a class in TypeScript?
Question 2
What does new Person() create here?
class Person {}
const p = new Person();Question 3
Which item can be inside a class?
Question 4
What logs?
class Box { size = 10 }
console.log(new Box().size);Question 5
What is the purpose of a constructor?
Question 6
What prints?
class A {
constructor() { console.log('init') }
}
new A();Question 7
What must a subclass call if it declares its own constructor?
Question 8
What error occurs here?
class Base {}
class Sub extends Base {
constructor() {}
}Question 9
Which modifier makes a class member only accessible inside the class itself?
Question 10
Which modifier allows access inside the class and subclasses?
Question 11
What happens?
class Car {
private speed = 10;
}
const c = new Car();
console.log(c.speed);Question 12
What does readonly do for class fields?
Question 13
What error occurs?
class Item {
readonly id = 1;
}
const i = new Item();
i.id = 5;Question 14
What are parameter properties?
Question 15
What is stored on the instance?
class User {
constructor(public name: string) {}
}
const u = new User('A');Question 16
What does a method represent in a class?
Question 17
What prints?
class Counter {
count = 1;
inc() { this.count++; }
}
const c = new Counter();
c.inc();
console.log(c.count);Question 18
Which statement about this binding in methods is correct?
Question 19
What prints?
class T {
x = 5;
getX = () => this.x;
}
console.log(new T().getX());Question 20
What keyword creates a subclass?
Question 21
What does super refer to?
Question 22
What prints?
class A { say() { return 'A' } }
class B extends A {
say() { return 'B' }
}
console.log(new B().say());Question 23
Abstract classes can:
Question 24
What error occurs?
abstract class Shape {}
const s = new Shape();Question 25
What must Circle implement?
abstract class Shape {
abstract area(): number;
}
class Circle extends Shape {}Question 26
What does an instance type represent?
Question 27
Which object matches structural typing?
Question 28
Static fields belong to:
Question 29
Which field type is shared across all instances?
Question 30
Why might you use classes instead of functions for object creation?
Question 31
Which statement describes instance fields?
Question 32
Classes compile to what underlying mechanism?
Question 33
What enforces compile-time typing for classes?
Question 34
Which statement is true about property initialisers?
Question 35
Which describes method overriding?
Question 36
What is required to override a method safely?
Question 37
How do classes support polymorphism?
Question 38
Which pattern uses a class to enforce a required method structure?
Question 39
What describes structural compatibility between classes?
Question 40
Why are classes useful in TypeScript projects?
