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 [Link];
B. package [Link];
C. package euAccesaOcaExamples;
D. package examplesocaaccesaeu;
2. What is the output of the following program?
1. package [Link];
2.
3. public class WorldPeaceUtilities {
4. public static void bringPeace() {
5. [Link]("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 [Link].*;
2. import [Link];
3. import static [Link].*;
4.
5. public class HelloWorld {
6. public static void main(String[] args) {
7. [Link]("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.
1
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. [Link] 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 [Link] can compile without any error?
//in file /root/com/foo/[Link]
1. package [Link];
2. public class X {
3. public static int LOGICID = 10;
4. public void apply(int i) {
5. [Link]("applied");
6. }
7. }
//in file /root/com/bar/[Link]
1. package [Link];
2. //1 <== INSERT STATEMENT(s) HERE
3. public class Y {
4. public static void main(String[] args) {
5. X x = new X();
6. [Link](LOGICID);
7. }
8. }
A. import static X;
B. import static [Link].*;
C. import static [Link].X.*;
D. import [Link].*;
E. import [Link];
2
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 commandline usages appropriately identify the classpath?
A. javac cp /project/classes/ [Link]
B. javac sp /project/classes/ [Link]
C. javac classpath /project/classes/ [Link]
D. javac classpaths /project/classes/ [Link]
9. What will the following code print when run?
1. public class TestClass {
2. public static long main(String[] args) {
3. [Link]("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 commandline 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
3
OCA Java SE 8 Study Group
1. Java Basics Self Test
12. The following are the complete contents of [Link] file. Which packages are
automatically imported?
1. class TestClass {
2. public static void main(String[] args) {
3. [Link]("hello");
4. }
5. }
A. [Link]
B. System
C. [Link]
D. [Link]
E. String
F. The package with no name.
4