What will happen when you attempt to compile and run the following code? class MyParent { int x, y; MyParent(int x, int y) { this.x = x; this.y = y; } public int addMe(int x, int y) { return this.x + x + y + this.y; } public int addMe(MyParent myPar) { return addMe(myPar.x, myPar.y); } } class MyChild extends MyParent { int z; MyChild (int x, int y, int z) { super(x,y); this.z = z; } public int addMe(int x, int y, int z) { return this.x + x + this.y + y + this.z + z; } public int addMe(MyChild myChi) { return addMe(myChi.x, myChi.y, myChi.z); } public int addMe(int x, int y) { return this.x + x + this.y + y; } } public class MySomeOne { public static void main(String args[]) { MyChild myChi = new MyChild(10, 20, 30); MyParent myPar = new MyParent(10, 20); int x = myChi.addMe(10, 20, 30); int y = myChi.addMe(myChi); int z = myPar.addMe(myPar); System.out.println(x + y + z); } }
Reveal answer
Fill a bubble to check yourself
Keep practicing — related questions
- What will happen if you attempt to compile and run the following code? class Base {} class Sub extends Base...
- What will happen if you attempt to compile and run the following code? class Base {} class Sub extends Base...
- Given: class Uber { static int y = 2; Uber(int x) { this(); y = y * 2; } Uber() { y++; } } class Minor exte...
- What is the output for the below code ? 1. public class A { 2. int add(int i, int j){ 3. return i+j; 4. } 5...
- Given the following, 1. class X { void dol() { } } 2. class Y extends X { void do2() { } } 3. 4. class Chro...
- What is the result of the following code? 1. public abstract class A { 2. private void doStuff() { 3. Syste...
- 1. class X { void do1() { } } 2. class Y extends X { void do2() { } } 3. 4. class Chrome { 5. public static...
- Which of the following, if inserted at the comment //Here will allow the code to compile and run without er...