Oracle 1Z0-808 Exam (page: 7)
Oracle Java SE 8 Programmer I
Updated on: 01-Sep-2025

Viewing Page 7 of 49

Which two actions will improve the encapsulation of a class?

  1. Changing the access modifier of a field from public to private
  2. Removing the public modifier from a class declaration
  3. Changing the return type of a method to void
  4. Returning a copy of the contents of an array or ArrayList instead of a direct reference

Answer(s): A,D


Reference:

http://www.tutorialspoint.com/java/java_access_modifiers.htm



Given:

public class ComputeSum {
public int x;
public int y;
public int sum;
public ComputeSum (int nx, int ny) {
x = nx; y =ny;
updateSum();
}
public void setX(int nx) { x = nx; updateSum();}
public void setY(int ny) { x = ny; updateSum();}
void updateSum() { sum = x + y;}
}
This class needs to protect an invariant on the sum field.
Which three members must have the private access modifier to ensure that this invariant is maintained?

  1. The x field
  2. The y field
  3. The sum field
  4. The ComputerSum ( ) constructor
  5. The setX ( ) method
  6. The setY ( ) method

Answer(s): C,E,F

Explanation:

The sum field and the two methods (setX and SetY) that updates the sum field.



Given the following array:

  1. Option A
  2. Option B
  3. Option C
  4. Option D
  5. Option E
  6. Option F

Answer(s): B,E

Explanation:

All the remaining options have syntax errors



Which statement best describes encapsulation?

  1. Encapsulation ensures that classes can be designed so that only certain fields and methods of an object are accessible from other objects.
  2. Encapsulation ensures that classes can be designed so that their methods are inheritable.
  3. Encapsulation ensures that classes can be designed with some fields and methods declared as abstract.
  4. Encapsulation ensures that classes can be designed so that if a method has an argument MyType x, any subclass of MyType can be passed to that method.

Answer(s): A



Given:

  1. Option A
  2. Option B
  3. Option C
  4. Option D
  5. Option E
  6. Option F

Answer(s): B,E

Explanation:

When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class (E). However, if it does not, then the subclass must also be declared abstract (B). Note: An abstract class is a class that is declared abstract--it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.



Viewing Page 7 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