Java MCQ on Scope rules and Accessibility modifiers


Mock java test, multiple-choice questions with answers on Scope rules and Accessibility modifiers for self-assessment and evaluation. Java self-evaluation test for OCJP aspirants.



Java self-evaluation test

Topic- Scope Rules and Accessibility modifiers in Java

The test consists of 11 questions.

No negative marking for this test.

No Time limit

The pass percentage is 70%

The correct answer with a description will be displayed after the answer has been marked.

Submit the test to calculate your score once you are done with all the questions.

Complexity Level- Medium



Q1: Static variables can be directly accessed by their names within an instance method of a class











Q2: 'this' reference keyword cannot be used in a static context/static block











Q3: 'super' reference keyword can be used in a static context/static block











Q4: The method parameters can be redeclared in the method body











Q5: The private member of a class can be accessible















Q6: The protected member of a class can be accessible

















Q7: The public member of a class can be accessible















Q8: Select the correct output of the execution of the below program:

public class testClass {

int instanceVar1;
static int staticVar1;

public static void main(String[] args) {
System.out.println(instanceVar1);
}
}














Q9: Select the correct output of the execution of the below program:

class c
{
private static int p1=20;
protected static int p2=40;

protected static int func1() {
return p1;
}
}

class testClass extends c{

protected static int func2() {
return p2+func1();
}

public static void main(String[] args ) {
System.out.println(func2());
}
}














Q10: The default member of a class (with no explicit member accessibility modifier) can be accessible

















Q11: Non-subclasses in other packages cannot access protected members from other packages