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.53 KB | None | 0 0
  1. class Person {
  2. private name : string;
  3. private age : number;
  4.  
  5. constructor(name: string, age: number){
  6. this.name = name;
  7. this.age =age;
  8. }
  9.  
  10. tellMyName(): string {
  11. return "I am " + this.name;
  12. }
  13. tellMyAge(): string {
  14. return "I am " + this.age + " years old";
  15. }
  16. }
  17. const person1 = new Person("John", 40);
  18. const person2 = new Person("Mary", 35);
  19.  
  20. console.log(person1.tellMyName());
  21. console.log(person1.tellMyAge());
  22. console.log(person2.tellMyName());
  23. console.log(person2.tellMyAge());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement