Class Members Having Different Access Levels - Java Object Oriented Design

Java examples for Object Oriented Design:Access Level

Description

Class Members Having Different Access Levels

Demo Code

public class Main {
  private int v1 = 10;
  int v2 = 20;/*from   www.j av a  2s  . c o  m*/
  protected int v3 = 30;
  public int v4 = 40;

  private void m1() {
    System.out.println("Inside m1():");
    System.out.println("v1 = " + v1 + ", v2 = " + v2 +
                       ", v3 = " + v3 + ", v4 = " + v4);
  }

  void m2() {
    System.out.println("Inside m2():");
    System.out.println("v1 = " + v1 + ", v2 = " + v2 +
                       ", v3 = " + v3 + ", v4 = " + v4);
  }

  protected void m3() {
    System.out.println("Inside m3():");
    System.out.println("v1 = " + v1 + ", v2 = " + v2 +
                       ", v3 = " + v3 + ", v4 = " + v4);
  }

  public void m4() {
    System.out.println("Inside m4():");
    System.out.println("v1 = " + v1 + ", v2 = " + v2 +
                       ", v3 = " + v3 + ", v4 = " + v4);
  }
}

Related Tutorials