Oracle certification · Exam 1z0-808

1z0-808 Mock Exam Page 4

Java SE 8 Programmer I

Free 1z0-808 mock exam questions 31–40, each with the answer and an explanation.

20 questions · 33 minutes · free, no sign-up

Free 1z0-808 questions

31–40 of 70 free
Question 31 Choose 3

Which three statements are true about the structure of a Java class?

 

Show answerHide answer

Correct answer: A, B, C

class can have only one private constructor.

A method can have the same name as a field.

A class can have overloaded static methods.

Explanation

A: Private constructors prevent a class from being explicitly instantiated by its
callers.
If the programmer does not provide a constructor for a class, then the system will always
provide a default, public no-argument constructor. To disable this default constructor,
simply add a private no-argument constructor to the class. This private constructor may be
empty.
B: The following works fine:
int cake() {
int cake=0;
return (1);
}
C: We can overload static method in Java. In terms of method overloading static method
are just like normal methods and in order to overload static method you need to provide
another static method with same name but different method signature.
Incorrect:
Not D: Only a public class in an application need to have a main method.
Not E:
Example:
class A
{
public string something;
public int a;
}
Q: What do you call classes without methods?
Most of the time: An anti pattern
Why? Because it faciliates procedural programming with "Operator" classes and data
structures. You separate data and behaviour which isn't exactly good OOP.
Often times: A DTO (Data Transfer Object)
Read only datastructures meant to exchange data, derived from a business/domain object.
Sometimes: Just data structure.
Well sometimes, you just gotta have those structures to hold data that is just plain and
simple and has no operations on it.
Not F: Fields need to be initialtized. If not the code will not compile.
Example:
Uncompilable source code - variable x might not have been initialized

Question 32 Choose 2

Which of the following data types will allow the following code snippet to compile?

Show answerHide answer

Correct answer: B, D

double

float

Explanation

Option B and D are the correct answer.
Since the variables I and j are floats, resultant will be float type too. So we have to use float
or primitive type which can hold float, such a primitive type is double, it has wider range
and also can hold floating point numbers, hence we can use double or float for the blank.
As explained above options B and D are correct.
long and int can't be used with floating point numbers so option A is incorrect.
Option E is incorrect as it have smaller range and also can't be used with floating point
numbers.hnpsy/docs.oracle.com/javase/tutorial/java/javaOO/variables.html

Question 33 Choose 1

Which of the following can fill in the blank in this code to make it compile?


Show answerHide answer

Correct answer: C

default

Explanation

From Java SE 8, we can use static and/or default methods in interfaces, but they should be
non abstract methods. SO in this case using default in blank is completely legal. Hence
option C is correct.
Option A is incorrect as given method is not abstract, so can't use abstract there.
Options B and E are incorrect as we can't have non abstract method interface if they are
not default or static.
https;//docs.oraclexom/javase/tutorial/java/Iandl/defaultmethods.html

Question 34 Choose 1

Given:

What is the result?

Show answerHide answer

Correct answer: B

10 : 22 : 22

Question 35 Choose 1

Given:

What is the result?

Show answerHide answer

Correct answer: C

5 4 5 6

Question 36 Choose 1

Given the code fragment:
public static void main(String[] args) {
int iArray[] = {65, 68, 69};
iArray[2] = iArray[0];
iArray[0] = iArray[1];
iArray[1] = iArray[2];
for (int element : iArray) {
System.out.print(element + " ");
}

Show answerHide answer

Correct answer: B

68, 65, 65

Question 37 Choose 1

Given:
public class Equal {
public static void main(String[] args) {
String str1 = "Java";
String[] str2 = {"J","a","v","a"};
String str3 = "";
for (String str : str2) {
str3 = str3+str;
}
boolean b1 = (str1 == str3);
boolean b2 = (str1.equals(str3));
System.out.print(b1+", "+b2);
}
What is the result?

Show answerHide answer

Correct answer: B

false, true

Explanation

strict equality.
equals compare state, not identity

Question 38 Choose 1

Which usage represents a valid way of compiling java source file with the name "Main"?

Show answerHide answer

Correct answer: A

 javac Main.java

Explanation


The compiler is invoked by the javac command. When compiling a Java
class, you must include the file name, which houses the main classes including the Java
extension. So to run Main.java file we have to use command in option A.
TO execute Java program we can use Java command but can't use it for compiling.
https://docs.oracle.com/javase/tutorial/getStarted/application/index.html

Question 39 Choose 1

Given:

What is the result?

Show answerHide answer

Correct answer: C

400.0 : 100.0

Question 40 Choose 1

Given:


What is the result?

Show answerHide answer

Correct answer: C

Out of limits
hEllOjAvA!

Full mock exam

Sit the 1z0-808 exam before exam day

Full-length mocks with the same number of questions and the same time limit as the real 1z0-808 exam. Every attempt draws a new set of questions from the full bank, so you can keep going until you pass comfortably.

Get full 1z0-808 mock exam
  • 65questions per mock
  • 105 mintime limit
  • 236questions in the bank
  • Newmock on every attempt