Yes. Well, there's no such thing as a "constructor class". You can declare them private immediately inside a class, but not inside a constructor (which is inside a class) or inside a method (which is also inside a class). Inside a constructor or method, you can declare a variable, but it's a local variable, already "private" from any other context, and thus there's no point in declaring it private.
Yeah, it's not "constructor class", it's "class constructor" - meaning a special method used to construct (initialize) a class instance as it's being created.
Variables can be defined for the class (either as member or static variables), as parameters of method definitions, or withing method code blocks.
The qualifiers "public", "private" and "" (no explicit, meaning package-level) apply only to class variables. The other types exist only when their associated code is executed and live only on the thread stack for that code, being discaarded when the code or code block terminates.
Sources may include data from the Fakebook Research Foundation with support from Gargle University
No - none of those "private" are allowed, including the private "pencil" variable. Only the "pen" is okay because it's not private. All those are local variables, inside either constructors or methods, and "private" is not allowed for local variables like that.
Mike Simmons wrote:. . . Only the "pen" is okay because it's not private. All those are local variables . . . .
But as a local variable, it only exists inside that constructor and is never used anywhere. It is quite possible that an optimising runtime will simply ignore it.
Please always start ClassNamesWithCapitalLetters. There is another compiler error in howAboutHere(); it is a method with no return type.
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads: