Utilize shorthand syntax in the constructor to automatically define class properties.
class Animal {
// 'public' automatically creates and assigns the property
constructor(public name: string) {}
// Method with explicit return type void
makeSound(): void {
console.log(`${this.name} makes a sound.`);
}
}
// Create an instance and call its method
const dog = new Animal("Dog");
dog.makeSound(); // Output: Dog makes a sound.