Home
6.
Which variables have a scope limited to a method?
  • A.
    Interface variables
  • B.
    Class variables
  • C.
    Instance variables
  • D.
    Local variables
  • Answer & Explanation
  • Report
Answer : [D]
Explanation :
Only local variables have such a small scope, making Option D the correct answer.
Report
Name Email  
7.
Which package is imported into every Java class by default?
  • A.
    java.util
  • B.
    java.lang
  • C.
    system.lang
  • D.
    java.system
  • Answer & Explanation
  • Report
Answer : [B]
Explanation :
The package java.lang is imported into every Java class, so Option B is correct. The other options must be explicitly imported. Option A exists but must be explicitly imported. Options C and D do not exist in the standard Java runtime.
Report
Name Email  
8.
Which of the following is not a valid code comment in Java?
  • A.
    // Add 5 to the result
  • B.
    /*** TODO: Fix bug 12312 ***/
  • C.
    # Add configuration value
  • D.
    /* Read file from system ****/
  • Answer & Explanation
  • Report
Answer : [C]
Explanation :
Java accepts Options A, B, and D as valid comments. Note that the /* */ syntax can have additional (and uneven) star (*) characters as shown in B and D. Option C is incorrect as hashtag (#) is not a valid comment character in Java.
Report
Name Email  
9.
Which statement about a valid .java file is true?
  • A.
    It can only contain one class declaration.
  • B.
    It can contain one public class declaration and one public interface definition.
  • C.
    It must define at least one public class.
  • D.
    It may define at most one public class.
  • Answer & Explanation
  • Report
Answer : [D]
Explanation :
A valid .java file may define any number of classes or interfaces but have at most one public class. It can also not define any public classes. For these reasons, Option A, B, and C are incorrect, leaving Option D as the only correct answer.
Report
Name Email  
10.
Given the following application, fill in the missing values in the table starting from the top and going downward.
package competition;
public class Robot {
static String weight = "A lot";
/* default */ double ageMonths = 5, ageDays = 2;
private static boolean success = true;
public void main(String[] args) {
final String retries = "1";
// P1
}
}
  • A.
    2,0,1
  • B.
    2,2,1
  • C.
    1,0,1
  • D.
    0,2,1
  • Answer & Explanation
  • Report
Answer : [B]
Explanation :
Notice in this question that main() is not a static method, therefore it can access both class and instance variables. Since there are two class variables and two instance variables defined, Option B is the correct answer.
Report
Name Email