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

    class Modifier
    {
    public int p;
    static int q;
    void cal(int n1, int n2)
    {
    p += n1;
    q += n2;
    }
    }
    public class static_keyword
    {
    public static void main(String args[])
    {
    Modifier obj1 = new Modifier();
    Modifier obj2 = new Modifier();
    obj1.p = 2;
    obj1.q = 3;
    obj1.cal(4, 5);
    obj2.p = 4;
    obj2.cal(4, 6);
    System.out.println(obj1.p + " " + obj2.q);
    }
    }
    1. 6 14
    2. 7 14
    3. 14 6
    4. 14 7
    5. None of these
Correct Option: A

Output: 6 14



Your comments will be displayed only after manual approval.