外部d 子类
private 私有 x x
public 共有
protected x

2.private

  1. class Preson{
  2. private name:String="list"
  3. public age:number=20
  4. }
  5. var p:Preson=new Preson();
  6. console.log(p);

private不可以访问

  1. class Student{
  2. private name:string="list"
  3. sayName():void{
  4. console.log(this.name);
  5. }
  6. }
  7. class MidStudent extends Student{
  8. getName(){
  9. console.log(this.name);
  10. }
  11. }
  12. var m:MidStudent=new MidStudent();
  13. m.getName();

3.protected

声明在类外部不可以访问

  1. class Student{
  2. protected name:string="list"
  3. sayName():void{
  4. console.log(this.name);
  5. }
  6. }
  7. var s:Student =new Student();
  8. console.log(s.sayName());

protected可以访问

  1. class Student{
  2. protected name:string="list"
  3. sayName():void{
  4. console.log(this.name);
  5. }
  6. }
  7. class MidStudent extends Student{
  8. getName(){
  9. console.log(this.name);
  10. }
  11. }
  12. var m:MidStudent=new MidStudent();
  13. m.getName();