Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class person
- {
- private name: string;
- private age: number;
- constructor(name: string, age: number)
- {
- this.name = name;
- this.age = age;
- }
- tellMyName(): string
- {
- return `I am ${this.name}`;
- }
- tellMyAge(): string
- {
- return `I am ${this.age} years old`;
- }
- }
- const person1 = new person ('John', 40);
- const person2 = new person ('Mary', 35);
- console.log(person1.tellMyName());
- console.log(person1.tellMyAge());
- console.log(person2.tellMyName());
- console.log(person2.tellMyAge());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement