Skip to main content

Posts

Showing posts with the label Access Modifiers

Access Modifiers

Access Modifiers | Java: Access Modifiers are controllers of data of variables, methods and classes. Those are four default, public, protected and private. Syntax:                                        access_madifier int x; Here is the Code: import java.io.*; class Main { public static void main (String[] args) { A a = new A(1); System.out.println(a.getX()); } } class A  {     private int x;     A(int x)     {         this.x = x;     }     public int getX()     {         return this.x;     } } Output: 1 Here is the Video: