1.

Can static variables be declared inside a local class?(a) Yes, with public access specifier(b) Yes, anywhere as required(c) No, not possible in private access specifier(d) No, not possible anywayThis question was posed to me in an online interview.I would like to ask this question from Local Class topic in chapter Class Members & Types of Object Oriented Programming

Answer»

The correct answer is (d) No, not possible anyway

The explanation is: No, the STATIC variables can’t be declared inside a local class. This is because each time the function is CALLED, all the variables get created again and are DESTROYED as soon as the function is RETURNED. This WOULD have been possible id the static variable was of function.



Discussion

No Comment Found

Related InterviewSolutions