Count how many objects of a class were created
QuizEasy-MediumJava onlyAsked in: Infosys
You want Counter.getCount() to return how many Counter objects have been created. Which design works?
- A
private static int countfield, incremented in the constructor, returned by astaticgetter - A
private int countfield, incremented in the constructor - A
staticcounter incremented in astaticblock - A local variable in the constructor
This question is part of Pro+
Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.