May 2021 1 26 Report
JAVA COMPUTER PROGRAMING?

Consider the following class definition:

public class Counter

{

private int myN;

public Counter( int n )

{

myN = n;

}

public Counter nextCounter()

{

return new Counter( myN + 1 );

}

public int getN()

{

return myN;

}

}

What is the value of t after the following code is executed?

int t = 0;

int i;

Counter c = new Counter( 10 );

for ( i = 0 ; i < 5 ; i++ )

{

c = c.nextCounter();

t = c.getN();

}

A. 15

B. 14

C. 10

D. 5

E. 4

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 Q2A.ES - All rights reserved.