Answers for "how to create a class with a constructor"

0

how to create a class with a constructor

class Car {

// fields  
  model: String;  
  doors: Number;  
  isElectric: Boolean;

constructor(model: String, doors: Number, isElectric: Boolean) {  
    this.model = model;  
    this.doors = doors;  
    this.isElectric = isElectric;  
  }

displayMake(): void {  
    console.log(`This car is ${this.model}`);  
  }

}
Posted by: Guest on June-01-2021

Code answers related to "how to create a class with a constructor"

Browse Popular Code Answers by Language