You are on page 1of 4

 

OCA Java SE 8 Study Group 
1. Java Basics ­ Self Test 
 
 
1. Which of the following respect the standard coding convention for package statements? 
A. package examples.oca.accesa.eu; 
B. package eu.accesa.oca.examples; 
C. package euAccesaOcaExamples; 
D. package examples­oca­accesa­eu; 
 
2. What is the output of the following program? 
1. package java.util; 
2.  
3. public class WorldPeaceUtilities { 
4.     public static void bringPeace() { 
5.         System.out.println("Peace!"); 
6.     } 
7.  
8.     public static void main(String[] args) { 
9.         bringPeace(); 
10.     } 
11. } 
A. Compilation fails at line 1. 
B. Exception is thrown at runtime. 
C. “Peace!” is printed on the standard output. 
 
3. What is the output of the following program? 
1. import java.lang.*; 
2. import java.lang.String; 
3. import static java.lang.System.*; 
4.  
5. public class HelloWorld { 
6.     public static void main(String[] args) { 
7.         out.println("Hello World!"); 
8.     } 
9. } 
A. Compilation fails at line 1. 
B. Compilation fails at line 2. 
C. Compilation fails at line 3. 
D. Compilation fails at line 7. 
E. “Hello World!” is printed on the standard output. 
 
 
   


 
OCA Java SE 8 Study Group 
1. Java Basics ­ Self Test 
 
 
4.  Which  of  the   following  are  correct   for  the  below  snippet  (suppose  FooImpl  is  a   public 
class; Foo and Bar are public interfaces): 
1. public class FOO_BAR extends FooImpl implements Foo, Bar { 
2. … 
3. } 
A. The class name doesn’t respect the standard Java naming convention 
B. The extends and implements clauses aren’t in the correct order 
C. The implemented interfaces must be separated by semicolons instead of colons 
 
5.  Which  of  the   following  commands  hide/don’t  use  the  command  window  when  starting  a 
program? 
A. javax.exe MainClass (for Windows) 
B. java MainClass & (for POSIX) 
C. javac MainClass (any system) 
D. java mainClass (for Windows) 
 
6. What should be inserted at //1 so that Y.java can compile without any error? 
//in file /root/com/foo/X.java 
1. package com.foo; 
2. public class X { 
3.    public static int LOGICID = 10; 
4.    public void apply(int i) { 
5.        System.out.println("applied"); 
6.    } 
7. } 
//in file /root/com/bar/Y.java 
1. package com.bar; 
2. //1 <== INSERT STATEMENT(s) HERE 
3. public class Y { 
4.    public static void main(String[] args) { 
5.        X x = new X(); 
6.        x.apply(LOGICID); 
7.    } 
8. } 
A. import static X; 
B. import static com.foo.*; 
C. import static com.foo.X.*; 
D. import com.foo.*; 
E. import com.foo.X.LOGICID; 
 
   


 
OCA Java SE 8 Study Group 
1. Java Basics ­ Self Test 
 
 
7. Which of the following commands print the usage information of the Java interpreter? 
A. java ­h 
B. javac ­h 
C. java ­­h 
D. java ­h helpme 
 
8. Which command­line usages appropriately identify the classpath? 
A. javac ­cp /project/classes/ MainClass.java 
B. javac ­sp /project/classes/ MainClass.java 
C. javac ­classpath /project/classes/ MainClass.java 
D. javac ­classpaths /project/classes/ MainClass.java 
 
9. What will the following code print when run? 
1. public class TestClass { 
2.  public static long main(String[] args) { 
3.     System.out.println("Hello"); 
4.     return 10L; 
5.  } 
6. } 
A. Hello 
B. It will print nothing. 
C. It will not compile 
D. It will throw an Error at runtime. 
E. None of the above. 
 
10 What does the zeroth element of the string array passed to the standard main method 
contain? 
A. The name of the class. 
B. The string "java". 
C. The number of arguments. 
D. The first argument of the argument list, if present. 
E. None of the above. 
 
11.  Which  command­line  invocations  of  the  Java  interpreter  return  the  version  of  the 
interpreter? 
A. java ­­version 
B. java ­version 
C. java ProgramName ­version 
D. java ­version ProgramName 
 
 
   


 
OCA Java SE 8 Study Group 
1. Java Basics ­ Self Test 
 
 
12. The following are the complete contents of TestClass.java file. Which packages are 
automatically imported? 
1. class TestClass { 
2.    public static void main(String[] args) { 
3.        System.out.println("hello"); 
4.    } 
5. } 
A. java.util 
B. System 
C. java.lang 
D. java.io 
E. String 
F. The package with no name. 

You might also like