Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. class person
  2. {
  3. private name: string;
  4. private age: number;
  5.  
  6. constructor(name: string, age: number)
  7. {
  8. this.name = name;
  9. this.age = age;
  10. }
  11.  
  12. tellMyName(): string
  13. {
  14. return `I am ${this.name}`;
  15. }
  16.  
  17. tellMyAge(): string
  18. {
  19. return `I am ${this.age} years old`;
  20. }
  21. }
  22.  
  23. const person1 = new person ('John', 40);
  24. const person2 = new person ('Mary', 35);
  25.  
  26. console.log(person1.tellMyName());
  27. console.log(person1.tellMyAge());
  28. console.log(person2.tellMyName());
  29. console.log(person2.tellMyAge());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement