ts重点学习67-类中的修饰符笔记
  TEZNKK3IfmPf 2023年11月14日 34 0
export default {}

class Person {
public name: string;
protected age: number;
private sex: string;

constructor(name: string, age: number, sex: string){
this.name = name;
this.age = age;
this.sex = sex;
}

say():void {
console.log(`我的名字是, 性别为, 今年岁了`);

}
}

let p = new Person("邱淑贞", 18, "女");
p.say();

class Student extends Person {
score: string
constructor(name: string, age: number, sex: string, score: string){
super(name, age, sex);
this.score = score;
}
show(): void {
console.log(this.name);
console.log(this.age);
console.log(this.score);
// console.log(this.sex);

}
}

// 思考题: 如果我们给 constructor 加上 protected 会出现什么情况?


// readonly
class PrintConsole {
readonly str1: string = "HTML, CSS, JS, VUE, REACT, NODE";
readonly str2: string;
readonly str3: string;
readonly str4: string;

constructor(str2: string, str3: string, str4: string){
this.str2 = str2;
this.str3 = str3;
this.str4 = str4;
}
}

let pc = new PrintConsole("我的头发去哪了,颈椎康复指南",
"35岁失业了该怎么办, 外卖月入一万也挺好",
"活着")
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月14日 0

暂无评论

推荐阅读
  TEZNKK3IfmPf   2023年11月14日   21   0   0 对象C++
  TEZNKK3IfmPf   2023年11月15日   47   0   0 python
  TEZNKK3IfmPf   2023年11月14日   19   0   0
  TEZNKK3IfmPf   2023年11月15日   112   0   0 设计模式java
  TEZNKK3IfmPf   2023年11月14日   76   0   0 java对象
  TEZNKK3IfmPf   2023年11月14日   62   0   0
  TEZNKK3IfmPf   2023年11月14日   26   0   0 django
  TEZNKK3IfmPf   2023年11月14日   27   0   0 定义
  TEZNKK3IfmPf   2023年11月14日   28   0   0 对象
TEZNKK3IfmPf