Complete the code to make the property accessible from anywhere.
class Car { [1] speed: number; constructor(speed: number) { this.speed = speed; } }
The public modifier allows the property to be accessed from anywhere.
Complete the code to restrict access to the property only within the class.
class BankAccount { [1] balance: number; constructor(balance: number) { this.balance = balance; } }
The private modifier restricts access to the property only inside the class.
Fix the error in the code by choosing the correct access modifier for the property to allow subclass access but not outside access.
class Animal { [1] sound: string; constructor(sound: string) { this.sound = sound; } } class Dog extends Animal { makeSound() { return this.sound; } }
The protected modifier allows access within the class and its subclasses, but not outside.
Fill both blanks to create a class with a private property and a public method to access it.
class User { [1] password: string; constructor(password: string) { this.password = password; } [2] getPassword() { return this.password; } }
The password is private to hide it, and the method is public to allow controlled access.
Fill all three blanks to define a class with a protected property, a public method to get it, and a subclass accessing it.
class Vehicle { [1] model: string; constructor(model: string) { this.model = model; } [2] getModel() { return this.model; } } class Car extends Vehicle { showModel() { return this.[3]; } }
The property is protected so the subclass can access it. The method is public to allow outside access. The subclass accesses the property by its name model.