Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Generate the output of the following program: class Add { protected int i; Add(int a) {i = a;} protected void addIt(int amount) {i /=

JAVA

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());

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

send employees to any university program for training?

Answered: 1 week ago

Question

How would we like to see ourselves?

Answered: 1 week ago

Question

How can we visually describe our goals?

Answered: 1 week ago

Question

What metaphors might describe how we work together?

Answered: 1 week ago