Java Program using protected keyword
In this program, You will learn how to implement the protected keyword in java.
Access modifiers in java: public, private, protected and default
Example: How to implement the protected keyword in java.
class A {
protected int x = 10;
}
class Main extends A {
void print() {
System.out.println("The x value is :" + x);
}
public static void main(String args[]) {
Main obj = new Main();
obj.print();
}
}
Output:
The x value is :10