Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Generate the output of the following program: class Add { protected int i; Add(i

ID: 3867493 • Letter: G

Question

Generate the output of the following program:                                                                                      

class Add {

     protected int i;

     Add(int a) {i = a;}

     protected void addIt(int amount) {i /= amount;}

     protected int getIt() {return i;}

}

class DAdd extends Add {

     private int i;

     DAdd(int a, int b) {

           super(a);

           i = b;

     }

     protected void addIt(int amount) {i = i * super.i + amount/ super.i ;}

     protected int getIt() {return i + 1;}

     protected void doubleIt(int amount) {addIt(2 * amount);}

}

public class TestAdder {

     public static void main(String args[]) {

           Add A = new Add(3);

           DAdd DA = new DAdd(1, 5);

           A.addIt(2);

           System.out.println(A.getIt());

           A = DA;

           A.addIt(2522);

           System.out.println(A.getIt());

           DA.doubleIt(211;

           System.out.println(A.getIt());

     }

}

Explanation / Answer

The output of the program is as follows:

The first System.out.println(A.getIt()); will print 1
The second System.out.println(A.getIt()); will print 2528
The third System.out.println(A.getIt()); will print 2950

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote