![]() In the above program, we have two classes Student, School. Student s=new Student() //create object to call constructor we try to access the private class members from outside the class. ![]() Private_Ex class contain the private variable and private method. In the above program, we have two classes Private_Ex, Vehicle_car. When the above code is executed, it produces the following results: compile time error Public int add(int a, int b, int c)//call the private method from outside class Program 1 //save this program name as TestJava In Java, class methods constructor data members are declared as public and can be accessed from anywhere.Įxample of Public access modifier in Java In Java language, there are four access modifiers In this tutorial, we will discuss Access modifier public private protected in Java programming language.Īccess modifier controls the access of a Class and, Methods, Constructor and data members from another class.
0 Comments
Leave a Reply. |