oracle 1z0-811 practice test

Java Foundations

Last exam update: Nov 18 ,2025
Page 1 out of 5. Viewing questions 1-15 out of 75

Question 1

Which statement is true about primitive variables?

  • A. They can be compared with the == operator.
  • B. They can be compared with the equals method only.
  • C. They cannot be compared.
  • D. They can be compared with the compareTo method only.
Mark Question:
Answer:

B


Explanation:
Reference: https://stackoverflow.com/questions/9690981/compare-two-primitive-long-variables-in-
java

User Votes:
A
50%
B
50%
C
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 2

Given the code fragment:

What is the result?

  • A. 2
  • B. 4
  • C. The program executes an infinite number of times.
  • D. 3
Mark Question:
Answer:

B

User Votes:
A
50%
B
50%
C
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 3

Identify two Java reserved words.

  • A. array
  • B. true
  • C. this
  • D. exception
  • E. string
Mark Question:
Answer:

B, C


Explanation:
Reference: https://www.computerhope.com/jargon/j/java_reserved_words.htm

User Votes:
A
50%
B
50%
C
50%
D
50%
E
50%
Discussions
vote your answer:
A
B
C
D
E
0 / 1000

Question 4

Which statement is true about a Java method?

  • A. It must be declared with an access modifier.
  • B. It cannot be defined within another method.
  • C. It must accept a parameter and return a value.
  • D. It cannot be defined as static final.
Mark Question:
Answer:

B


Explanation:
Reference: https://www.quora.com/Can-we-define-a-function-within-another-function-in-Java

User Votes:
A
50%
B
50%
C
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 5

Given:

And the code fragment:

Which code fragment can be inserted at line n1 to enable the code to print All the best?

  • A. void writeMsg();
  • B. Messenger.writeMsg();
  • C. writeMsg();
  • D. m.writeMsg();
Mark Question:
Answer:

B

User Votes:
A
50%
B
50%
C
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 6

Given the code fragment:

Which two code fragments are valid at line 2?
A.
for (int count = 0; count < 5; count++) {
System.out.print(count);
}
B.
package p1;
C.
import java.util.*;
public void display() {
List<Integer> nums = new ArrayList<> ();
}
D.
{
private int num;
}
E.
private String name = “John”;
public void display() {
System.out.print(name);
}

Mark Question:
Answer:

B, E

User Votes:
Discussions
vote your answer:
0 / 1000

Question 7

You have been asked to develop a Java program that prints the elements of an array in reverse order.
Which looping statement cannot be used to meet the requirement?

  • A. enhanced for
  • B. standard for
  • C. while
  • D. do-while
Mark Question:
Answer:

D


Explanation:
Reference: https://www.javatpoint.com/java-program-to-print-the-elements-of-an-array-in-reverse-
order

User Votes:
A
50%
B
50%
C
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 8

Given the code fragment:

Which statement is true?
A.
The code results in a compilation error. To make it compile, insert at line n1:
import java.lang.Math;
import java.lang.Random;
B.
The code compiles successfully
C.
The code results in a compilation error. To make it compile, insert at line n1:
import java.lang;
import java.util;
D.
The code results in a compilation error. To make it compile, insert at line n1:
import java.util.*;

Mark Question:
Answer:

B

User Votes:
Discussions
vote your answer:
0 / 1000

Question 9

Given the code fragment:

What is the result?

  • A. pen pencil erasers paper
  • B. paper pen pencil erasers
  • C. A compilation error occurs.
  • D. A runtime exception is thrown.
Mark Question:
Answer:

D

User Votes:
A
50%
B
50%
C
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 10

Given the code fragment:

Which code fragment, when inserted at line n1, enables the code to print Java Programming:1?

  • A. System.out.println(name + “:” + count);
  • B. System.out.println(c.name + “:” + count);
  • C. System.out.println(c.name + “:” + Course.count);
  • D. System.out.println(Course.name + “:” + c.count);
Mark Question:
Answer:

C

User Votes:
A
50%
B
50%
C
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 11

Given:

What is the result?

  • A. [null:-]
  • B. [ : ]
  • C. [null:null]
  • D. [:null]
Mark Question:
Answer:

A

User Votes:
A
50%
B
50%
C
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000

Question 12

Which two Java reserved words are used to implement encapsulation?

  • A. final
  • B. static
  • C. public
  • D. extends
  • E. private
Mark Question:
Answer:

C, E


Explanation:
Reference: https://learn.saylor.org/mod/page/view.php?id=22044

User Votes:
A
50%
B
50%
C
50%
D
50%
E
50%
Discussions
vote your answer:
A
B
C
D
E
0 / 1000

Question 13

Given the code fragment:

Which code fragment can be inserted at line n1 to enable the code to print 0.0?
A.
Ball b = null;
b.weight = 0.0;
B.
Ball.weight = 0.0;
C.
Ball b = new Ball(0.0);
D.
Ball b = new Ball();

Mark Question:
Answer:

D

User Votes:
Discussions
vote your answer:
0 / 1000

Question 14

Which two statements are true about the Java Runtime Environment (JRE)?

  • A. It is responsible for garbage collection.
  • B. It interprets bytecode stored in a .class file.
  • C. It contains the JDK and Java APIs.
  • D. It is platform independent.
  • E. You must install the JRE to compile a .java file.
Mark Question:
Answer:

B, D


Explanation:
Reference: https://en.wikipedia.org/wiki/Java_virtual_machine

User Votes:
A
50%
B
50%
C
50%
D
50%
E
50%
Discussions
vote your answer:
A
B
C
D
E
0 / 1000

Question 15

Identify two features of Java.

  • A. architecture dependent
  • B. platform independent
  • C. single threaded
  • D. robust
Mark Question:
Answer:

B, D


Explanation:
Reference: https://www.javatpoint.com/features-of-java

User Votes:
A
50%
B
50%
C
50%
D
50%
Discussions
vote your answer:
A
B
C
D
0 / 1000
To page 2