Oracle 1Z0-808 Exam (page: 3)
Oracle Java SE 8 Programmer I
Updated on: 29-Aug-2025

Viewing Page 3 of 49

Given the code fragment:



What is the result?

  1. 10 8 6 4 2 0
  2. 10 8 6 4 2
  3. AnArithmeticException is thrown at runtime
  4. The program goes into an infinite loop outputting: 10 8 6 4 2 0. . .
  5. Compilation fails

Answer(s): B



Given:



Which code fragment, when inserted at line 14, enables the code to print Mike Found?

  1. int f = ps.indexOf {new patient ("Mike")};
  2. int f = ps.indexOf (patient("Mike"));
  3. patient p = new Patient ("Mike");
    int f = pas.indexOf(P)
  4. int f = ps.indexOf(p2);

Answer(s): C



Given:

  1. Option A
  2. Option B
  3. Option C
  4. Option D

Answer(s): C



Given the for loop construct:
for ( expr1 ; expr2 ; expr3 ) {
statement;
}
Which two statements are true?

  1. This is not the only valid for loop construct; there exits another form of for loop constructor.
  2. The expression expr1 is optional. it initializes the loop and is evaluated once, as the loop begin.
  3. When expr2 evaluates to false, the loop terminates. It is evaluated only after each iteration through the loop.
  4. The expression expr3 must be present. It is evaluated after each iteration through the loop.

Answer(s): B,C

Explanation:

The for statement have this forms:
for (init-stmt; condition; next-stmt) {
body
}
There are three clauses in the for statement.
The init-stmt statement is done before the loop is started, usually to initialize an iteration variable.
The condition expression is tested before each time the loop is done. The loop isn't executed if the boolean expression is false (the same as the while loop). The next-stmt statement is done after the body is executed. It typically increments an iteration variable.



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

  1. A class can have only one private constructor.
  2. A method can have the same name as a field.
  3. A class can have overloaded static methods.
  4. A public class must have a main method.
  5. The methods are mandatory components of a class.
  6. The fields need not be initialized before use.

Answer(s): A,B,C

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



Viewing Page 3 of 49



Share your comments for Oracle 1Z0-808 exam with other users:

Mchal 7/20/2023 3:38:00 AM

some questions are wrongly answered but its good nonetheless
POLAND


Merry 7/30/2023 6:57:00 AM

good questions
Anonymous