Answer to Question #183604 in Java | JSP | JSF for Bill

Question #183604

*Based on answer choices A-E, what is the code's output?


6. Given the following code, the output is __.


class Apple { static int i; }

class Fruits

{

public static void main(String args[])

{

Apple.i = 2;

Apple a1 = new Apple();

a1.i++;

System.out.println(a1.i);

}

}


A. 5

B. 4

C. 2

D. 3

E. 0


1
Expert's answer
2021-04-25T06:43:31-0400

This code will output 3, so right answer is D.


This will happened because `i` is static variable, so its value is common among all instances of the class `Apple`.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog