Public modifier in TypeScript

Properties and methods declared via the public modifier are available for reading and writing outside the class. Let's see in practice. Let's make our class have a public property name:

typescriptclass User {
  public name: string = '';
}

Let's create an object of the class:

typescriptlet user = new User();

Let's change the value of the property:

typescriptuser.name = 'john';

Let's read the property:

typescriptconsole.log(user.name);
Задание 1

Create a class User that will contain public properties with the user's name and year of birth. Create a public method getAge that will get the user's age based on their year of birth.