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 :: java sort method 
Java :: what is static setter and getter examples in java 
Java :: get intersection of two lists java 
Java :: spring convert page to list 
Java :: how to output a list in java 
Java :: how to disable screenshot in react native 
Java :: check if optional is empty java 
Java :: java run jar with args 
Java :: how to check duplicate string in java 
Java :: java set classpath 
Java :: Remove an element at a specific index from an array in Java 
Java :: android studio reg get float from numeric string 
Java :: how to find the length of an array in java 
Java :: add recyclerview in fragment 
Java :: MyArrayList 
Java :: generate random number in java within a range without repeating with android studio 
Java :: nqueen problem with python 
Java :: could not find java in a java_home at /opt/java/openjdk/bin/java docker sonarqube 
Java :: default java keystore 
Java :: how to install clojure on linux 
Java :: using java stream filter to find the sum of property 
Java :: android java show hide keyboard in AndroidManifest 
Java :: how to generate random large string in java 
Java :: how to hash string in java 
Java :: java regex for ip address 
Java :: show all spring boot beans 
Java :: Java comment vérifier une égalité de String 
Java :: my maven project give error when adding javax.xml.bind dependency 
Java :: copy text from header tag in javacript 
Java :: java stream 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =