Bird
0
0

Which of the following method declarations correctly overrides a parent method public int calculate(int x)?

easy📝 Syntax Q12 of 15
Java - Polymorphism
Which of the following method declarations correctly overrides a parent method public int calculate(int x)?
Apublic int calculate(int x) { return x * 2; }
Bpublic void calculate(int x) { System.out.println(x); }
Cpublic int calculate(double x) { return (int)x; }
Dstatic public int calculate(int x) { return x + 1; }
Step-by-Step Solution
Solution:
  1. Step 1: Match method signature exactly

    The overriding method must have the same name and parameter types: calculate(int x).
  2. Step 2: Check return type and modifiers

    Return type must be int and method must not be static.
  3. Final Answer:

    public int calculate(int x) { return x * 2; } -> Option A
  4. Quick Check:

    Exact signature and return type = A [OK]
Quick Trick: Match method name, parameters, and return type exactly [OK]
Common Mistakes:
  • Changing return type to void
  • Changing parameter type
  • Making method static

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes