1Z0-803 · Question #221
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 Syst
The correct answer is A. Calc c = new Calc(); D. Mid m1 = 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);
How the community answered
(33 responses)- A67% (22)
- B3% (1)
- C18% (6)
- E12% (4)
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
Topics
Community Discussion
No community discussion yet for this question.