nerdexam
Exams1Z0-803Questions#229
Oracle

1Z0-803 · Question #229

1Z0-803 Question #229: Real Exam Question with Answer & Explanation

The correct answer is A: private int num;public int getNum() {return num;}. Not B: illegal combination of modifiers: protected and public not C: setNum method cannot be private. not E: getNum method cannot be private.

Question

Given: class Base { // insert code here } public class Derived extends Base{ public static void main(String[] args) { Derived obj = new Derived(); obj.setNum(3); System.out.println("Square = " + obj.getNum() * obj.getNum()); } } Which two options, when inserted independently inside class Base, ensure that the class is being properly encapsulated and allow the program to execute and print the square of the number?

Options

  • Aprivate int num;public int getNum() {return num;}
  • Bpublic int num;protected public int getNum() {return num;}
  • Cprivate int num;public int getNum() {return num;}private
  • Dprotected int num;public int getNum() {return num;}public
  • Eprotected int num;private int getNum() {return num;}public

Explanation

Not B: illegal combination of modifiers: protected and public not C: setNum method cannot be private. not E: getNum method cannot be private.

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice