- Home
- Programming
- OCA Java SE8
16.
Given that the current directory is /user/home, with an application Java file in
/user/home/Manager.java that uses the default package, which are the correct
commands to compile and run the application in Java?
- A.javac Manager
java Manager - B.javac Manager.java
java Manager - C.javac Manager
java Manager.class - D.javac Manager.java
java Manager.class
- Answer & Explanation
- Report
Answer : [B]
Explanation :
Explanation :
The compilation command requires the full or relative name of the file, including the .java extension, making Options A and C incorrect. The execution command requires the class name without a filename extension, making Option D incorrect. Option B is the only correct set of compilation and execution commands. |
17.
Structuring a Java class such that only methods within the class can access its
instance variables is referred to as _______.
- A.platform independence
- B.object orientation
- C.inheritance
- D.encapsulation
- Answer & Explanation
- Report
Answer : [D]
Explanation :
Explanation :
Encapsulation is the technique of removing access to a class’s instance variables from processes outside the class, making Option D the correct answer. |
18.
What is the output of the following code snippet?
String tree = "pine";
int count = 0;
if (tree.equals("pine")) {
int height = 55;
count = count + 1;
}br /> system.out.print(height + count);
String tree = "pine";
int count = 0;
if (tree.equals("pine")) {
int height = 55;
count = count + 1;
}br /> system.out.print(height + count);
- A.1
- B.55
- C.56
- D.It does not compile.
- Answer & Explanation
- Report
Answer : [D]
Explanation :
Explanation :
The height variable is declared within the if-then statement block. Therefore, it cannot be referenced outside the if-then statement and the code does not compile. |
19.
Which of the following is true of a Java bytecode file?
- A.It can be run on any computer with a compatible JVM.
- B.It can only be executed on the same type of computer that it was created on.
- C.It can be easily read and modified in a standard text editor.
- D.It requires the corresponding .java that created it to execute.
- Answer & Explanation
- Report
Answer : [A]
Explanation :
Explanation :
A Java bytecode file is a binary encoded set of instructions designed to be run on any computer with a compatible JVM, making Option A the only correct answer. By compatible JVM, we mean one capable of running the class file. For example, a Java 6 JVM may have trouble executing a Java 8 compiled file. Option B is incorrect, and is more a facet of machine language compiled programming classes. Option C is also incorrect as binary data is not particularly human readable. Finally, Option D is incorrect as the compiled file can be distributed without its .java source file and execute without issue. |
20.
What is the correct character for terminating a statement in Java?
- A.A colon (:)
- B.An end-of-line character
- C.A tab character
- D.A semicolon (;)
- Answer & Explanation
- Report
Answer : [D]
Explanation :
Explanation :
Unlike with some other programming languages, the proper way to terminate a line of code is with a semicolon (;), making D the only correct answer. |