Answers for "public private protected in java"

1

java protected private public

public      >> class, package, subclass (same pkg), subclass (diff pkg), world
protected   >> class, package, subclass (same pkg), subclass (diff pkg)
no modifier >> class, package, subclass (same pkg)
private     >> class
Posted by: Guest on August-31-2021
1

java protected private public

public      >> class, package, subclass (same pkg), subclass (diff pkg), world
protected   >> class, package, subclass (same pkg), subclass (diff pkg)
no modifier >> class, package, subclass (same pkg)
private     >> class
Posted by: Guest on August-31-2021
1

protected in java

//The protected keyword is an access modifier used for attributes, 
//methods and constructors, 
//making them accessible in the same package and subclasses.

class Person {
  protected String fname = "John";
  protected String lname = "Doe";
  protected String email = "[email protected]";
  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);
  }
}
Posted by: Guest on December-11-2020
1

protected in java

//The protected keyword is an access modifier used for attributes, 
//methods and constructors, 
//making them accessible in the same package and subclasses.

class Person {
  protected String fname = "John";
  protected String lname = "Doe";
  protected String email = "[email protected]";
  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);
  }
}
Posted by: Guest on December-11-2020

Code answers related to "public private protected in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language