Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. class Person {
  2. private firstName: string;
  3. private lastName: string;
  4. private birthDate: Date;
  5.  
  6. constructor(firstName: string, lastName: string, birthDate: Date) {
  7. this.firstName = firstName;
  8. this.lastName = lastName;
  9. this.birthDate = birthDate;
  10. }
  11.  
  12. getFirstName(): string {
  13. return this.firstName;
  14. }
  15.  
  16. getLastName(): string {
  17. return this.lastName;
  18. }
  19.  
  20. getBirthDate(): Date {
  21. return this.birthDate;
  22. }
  23.  
  24. setFirstName( firstName: string ) {
  25. this.firstName = firstName;
  26. }
  27.  
  28. setLastName( lastName: string ) {
  29. this.lastName = lastName;
  30. }
  31. }
  32.  
  33. let person1 = new Person("George", "Martin", new Date("2019-08-03"));
  34.  
  35. console.log( person1.getFirstName() );
  36.  
  37. person1.setFirstName("Brandon");
  38.  
  39. console.log( person1.getFirstName() );
  40.  
  41. class Employee extends Person {
  42. private department: string = "";
  43.  
  44. constructor(
  45. firstName: string,
  46. lastName: string,
  47. birthDate: Date,
  48. department?: string ) {
  49.  
  50. super(firstName, lastName, birthDate);
  51.  
  52. if ( department ) this.department = department;
  53. }
  54.  
  55. setDepartment( department: string ) {
  56. this.department = department;
  57. }
  58.  
  59. getDepartment(): string {
  60. return this.department;
  61. }
  62. }
  63.  
  64. let emp1 = new Employee( "Mary Jane", "Watson", new Date("1965-06-01") );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement