Which of the following access modifiers is not used in Java? code example
Example 1: access modifiers in java
Example of private access modifier:
class Demo
{
private void display()
{
System.out.println("Hello world java");
}
}
public class PrivateAccessModifierExample
{
public static void main(String[] args)
{
Demo obj = new Demo();
System.out.println(obj.display());
}
}
Example 2: What access modifiers can be used for class
We can use only two access modifiers for class public and default.
public: A class with public modifier can be visible
1) In the same class
2) In the same package subclass
3) In the same package nonsubclass
4) In the different package subclass
5) In the different package non subclass.
default : A class with default modifier can be accesed
1) In the same class
2) In the same package subclass
3) In the same package nonsubclass
4) In the different package subclass
5) In the different package non subclass.