| 类 | 外部d | 子类 | |||
|---|---|---|---|---|---|
| private | 私有 | √ | x | x | |
| public | 共有 | √ | √ | √ | |
| protected | √ | x | √ |
2.private
class Preson{private name:String="list"public age:number=20}var p:Preson=new Preson();console.log(p);
private不可以访问
class Student{private name:string="list"sayName():void{console.log(this.name);}}class MidStudent extends Student{getName(){console.log(this.name);}}var m:MidStudent=new MidStudent();m.getName();
3.protected
声明在类外部不可以访问
class Student{protected name:string="list"sayName():void{console.log(this.name);}}var s:Student =new Student();console.log(s.sayName());
protected可以访问
class Student{protected name:string="list"sayName():void{console.log(this.name);}}class MidStudent extends Student{getName(){console.log(this.name);}}var m:MidStudent=new MidStudent();m.getName();
