Declaration and Access Control in Java

Answer all questions carefully. After submission, you will see a detailed result and answer review.

Question 1
A method within a class is only accessible by classes that are defined within the same package as the class of the method. Which one of the following is used to enforce such restriction?
Question 2
What can directly access and change the value of the variable qusNo? <pre class="prettyprint"> package com.mypackage; public class Test{ private int qusNo = 100; } </pre>
Question 3
Consider the following two classes declared and defined in two different packages, what can be added in class B to form what considered a correct access to class A from main() method of class B? <pre class="prettyprint"> package subPackage; public class A { } package anotherPackage; // line 1 public class B{ public static void main(String[] args){ // line 2 } } </pre> 1. At line1 add noting; At line2 add: new A();<br />2. At line 1 add: import package.*; at line
Question 4
Choose all the lines which if inserted independently instead of "//insert code here" will allow the following code to compile: <pre class="prettyprint"> public class Test{ public static void main(String args[]){ add(); add(1); add(1, 2); } // insert code here } </pre>
Question 5
What will be the output for the below code? <pre class="prettyprint"> public class Test{ static{ int a = 5; } public static void main(String[] args){ System.out.println(a); } } </pre>
Question 6
Which statements are most accurate regarding the following classes? <pre class="prettyprint"> class A{ private int i; protected int j; } class B extends A{ private int k; protected int m; } </pre>
Question 7
What will be the output for the below code? <pre class="prettyprint"> static public class Test{ public static void main(String[] args){ char c = 'a'; switch(c){ case 65 : System.out.println("one");break; case 'a': System.out.println("two");break; case 3 : System.out.println("three"); } } } </pre>
Question 8
Choose the correct statement <pre class="prettyprint"> public class Circle{ private double radius; public Circle(double radius){ radius = radius; } } </pre>
Question 9
You have the following code in a file called Test.java <pre class="prettyprint"> class Base{ public static void main(String[] args){ System.out.println("Hello"); } } public class Test extends Base{} </pre> What will happen if you try to compile and run this?
Question 10
Name the keyword that makes a variable belong to a class, rather than being defined for each instance of the class.