Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java protected

/* similar to private keyword, but also lets both:
  - subclasses
  - classes in same package
  access the variable, method or constructor */

class Superclass {
  protected int myNumber = 5;
}

class Subclass extends SuperClass {
  // has access to myNumber
}

class InAnotherPackage {
  // doesn't have access to myNumber
}
 
PREVIOUS NEXT
Tagged: #java #protected
ADD COMMENT
Topic
Name
9+4 =