Modifier Types


  1. What is the output of this program?

    class static_Access
    {
    static int p;
    static int q;
    void add(int n1, int n2)
    {
    p = n1 + n2;
    q = p + n2;
    }
    }
    public class static_output
    {
    public static void main(String args[])
    {
    static_Access obj1 = new static_Access();
    static_Access obj2 = new static_Access();
    int n1 = 5;
    obj1.add(n1, n1 + 2);
    obj2.add(6, n1);
    System.out.println(obj1.p + " " + obj2.q);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Output: 11 16


  1. Which of these is used as default for a member of a class if no access specifier is used for it?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    When we pass an argument by call-by-value a copy of argument is made into the formal parameter of the subroutine and changes made on parameters of subroutine have no effect on original argument, they remain the same.



  1. Which of these access specifiers must be used for main() method?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    main() method must be specified public as it called by Java run time system, outside of the program. If no access specifier is used then by default member is public within its own package & cannot be accessed by Java run time system.


  1. Which of these is used to access member of class before object of that class is created?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    static



  1. Which of the following modifier means a particular variable cannot be accessed within the package?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Private variables are accessible only within the class.