Protected

The new protected modifier in classes works like it does in familiar languages like C++, C#, and Java. A protected member of a class is visible only inside subclasses of the class in which it is declared:

  1. class Thing {
  2. protected doSomething() { /* ... */ }
  3. }
  4. class MyThing extends Thing {
  5. public myMethod() {
  6. // OK, can access protected member from subclass
  7. this.doSomething();
  8. }
  9. }
  10. var t = new MyThing();
  11. t.doSomething(); // Error, cannot call protected member from outside class