Write a program to show Access Specifiers (Public, Private, Protected) in Java
class Test{
private int number;
public int number1;
private void Testmethod(){
System.out.println("I want to print the private variable within this class : " +number);
}
public void AccessPrivateMethod()
{
System.out.println("We can access private method declared in this class here : ");
Testmethod();
}
void noSpecifierMethod(){
System.out.println("I can access private method from a nonspecifier method too : ");
Testmethod();
}
}
class mainClass {
public static void main(String[] args){
Test t = new Test();
t.AccessPrivateMethod();
System.out.println("I can print the class variable : "+t.number1);
}
}
Post a Comment