What output is produced by the following code?   Explain how it works. public class A { int a...

90.2K

Verified Solution

Question

Programming

What output is produced by the following code?  Explain how it works.

public class A {

int a = 1;

int b = 2;

public int getSum(int a, int b) {

    this.a+=a;

    this.b+=b;

    return this.a + this.b;

}

}

public class B extends A {

int a = 3;

int b = 4;

public int getSum(int a, int b) {

    this.b=a;

    super.b=b+b;

    return super.a+this.b;

}

}

public class q2 {

public static void main(String[] args){

A a = new A();

B b = new B();

System.out.println(a.a + \" \"+ b.b);

System.out.println(a.getSum(a.a,b.b));  

System.out.println(a.b + \" \"+ b.b);

System.out.println(b.getSum(a.b,b.b));

System.out.println(a.a+\"\"+a.b + \" \" +b.a+\"\"+b.b);

}

}

Answer & Explanation Solved by verified expert
3.7 Ratings (625 Votes)
    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students