Search
 
SCRIPT & CODE EXAMPLE
 

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
}
Comment

Java protected Keyword

class Person {
  protected String fname = "John";
  protected String lname = "Doe";
  protected String email = "john@doe.com";
  protected int age = 24;
}

class Student extends Person {
  private int graduationYear = 2018;
  public static void main(String[] args) {
    Student myObj = new Student();
    System.out.println("Name: " + myObj.fname + " " + myObj.lname);
    System.out.println("Email: " + myObj.email);
    System.out.println("Age: " + myObj.age);
    System.out.println("Graduation Year: " + myObj.graduationYear);
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: Hourglass Java 
Java :: running sum of 1d array 
Java :: cannot find symbol variable log 
Java :: how to set radio button checked in android programmatically 
Java :: 8.1.1. Declaring an Array¶ 
Java :: springdoc 
Java :: java create new arraylist with elements 
Java :: timestamp java jpa 
Java :: java leap year 
Java :: double.parsedouble in java 
Java :: arrays in java 
Java :: How to find the prime factors of a number in Java? 
Java :: rotate a linked list 
Java :: array.sort in java 
Java :: java subscript numbers 
Java :: jtable get get row 
Java :: android application class 
Java :: javafx main class 
Java :: scanner.hasnext() 
Java :: volley library 
Java :: fragment to fragment 
Java :: file append in java 
Java :: immutable map java 
Java :: skip values in a for loop java 
Java :: login and logout react native and firebase 
Java :: java wait for user input 
Java :: retrofit post header 
Java :: java exception 
Java :: how to use user uid in android 
Java :: how to get 2 decimal places in java 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =