nerdexam
Oracle

1Z0-851 · Question #260

Given: public class SuperCalc { protected static int multiply(int a, int b) { return a * b;} } and: public class SubCalc extends SuperCalc{ public static int multiply(int a, int b) { int c =…

The correct answer is E. Compilation fails because of an error in line 22. Cannot use super in a static context

Class Design

Question

Given: public class SuperCalc { protected static int multiply(int a, int b) { return a * b;} } and: public class SubCalc extends SuperCalc{ public static int multiply(int a, int b) { int c = super.multiply(a, b); return c; } } and: SubCalc sc = new SubCalc (); System.out.println(sc.multiply(3,4)); System.out.println(SubCalc.multiply(2,2)); What is the result?

Options

  • A12
  • BThe code runs with no output.
  • CAn exception is thrown at runtime.
  • DCompilation fails because of an error in line 21.
  • ECompilation fails because of an error in line 22.
  • FCompilation fails because of an error in line 31.

How the community answered

(41 responses)
  • B
    10% (4)
  • C
    5% (2)
  • D
    2% (1)
  • E
    80% (33)
  • F
    2% (1)

Explanation

Cannot use super in a static context

Topics

#static methods#super keyword#method hiding#inheritance

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice