Home » JAVA Programming » Modifier Types » Question
  1. What is the output of this program?

    class access_Example
    {
    public int p;
    private int q;
    void calc(int n1, int n2)
    {
    p = n1 + 1;
    q = n2;
    }
    }
    public class access_specifier
    {
    public static void main(String args[])
    {
    access_Example obj = new access_Example();
    obj.cal(5, 7);
    System.out.println(obj.p + " " + obj.q);
    }
    }
    1. 5 7
    2. 7 7
    3. Compiletime error
    4. Runtime error
    5. None of these
Correct Option: C

access_specifier.java:16: error: cannot find symbol
obj.cal(5, 7);
^
symbol: method cal(int,int)
location: variable obj of type access_Example
access_specifier.java:17: error: q has private access in access_Example
System.out.println(obj.p + " " + obj.q);
^
2 errors



Your comments will be displayed only after manual approval.