Answer is C.
Although executing the code does not produce the exact print reported. The only plausible answer is option C.
Because the 'qty' variable needs to be static for the code to at least compile.
Note that this variable is not declared as an attribute of the class, so it could not be called in the printStock() method, which causes the compilation error. For it to be enclosed in this method, it needs to be declared in the class, which is what option C proposes.
The answer is C, to perform the operation, the variables must be static to refer to a single value and the method must also be static, otherwise, variables that are static cannot be used inside it.
Methods no need to be static in order to use static variables. However, static methods cannot use instance variables.
upvoted 2 times
...
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
af8c3f3
3 months, 4 weeks agocarloswork
2 years, 2 months agocarloswork
2 years, 2 months agoiSnover
2 years, 3 months agoalex_au
2 years, 3 months ago