319,098 views
34 votes
34 votes
What is output? Item jar = new Item(); Item ball = new Item(); System.out.println(Item.count); public class Item{ public static int count = 1; public Item(){ count++; } } Group of answer choices 1 Error: syntax error 3 2

User Saykor
by
2.8k points

1 Answer

6 votes
6 votes

Answer:

It's 3

Step-by-step explanation:

now if you pay attention, you've assigned count as 1 in the beginning and you've asked the class to increase the count variable by 1

and when the program is compiled the code is going to count ball and Jar as numbers

mean jar.count is 2

and ball.count is 3

that's all

User Uwe Geuder
by
3.1k points