nerdexam
Exams1Z0-803Questions#221
Oracle

1Z0-803 · Question #221

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

The correct answer is A: Calc c = new Calc();. Not B: circular definition of n3. Not C: Compilation error. lineCalc c = new Mid(); Not E: Compilation error. lineint n3 = Calc.findMid(n1, n2); non-static method findMid(int,int) cannot be referenced from a static context

Question

Given: class Mid { public int findMid(int n1, int n2) { return (n1 + n2) / 2; } } public class Calc extends Mid { public static void main(String[] args) { int n1 = 22, n2 = 2; // insert code here System.out.print(n3); } } Which two code fragments, when inserted at // insert code here, enable the code to compile and print 12?

Options

  • ACalc c = new Calc();
  • Bint n3 = super.findMid(n1,n3);
  • CCalc c = new Mid();
  • DMid m1 = new Calc();
  • Eint n3 = Calc.findMid(n1, n2);

Explanation

Not B: circular definition of n3. Not C: Compilation error. lineCalc c = new Mid(); Not E: Compilation error. lineint n3 = Calc.findMid(n1, n2); non-static method findMid(int,int) cannot be referenced from a static context

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice