Page 1 of 1

About Question enthuware.ocajp.i.v8.2.835 :

Posted: Sun Jun 10, 2018 11:42 am
by walltearer
The question asks about a variable: "Which of the following can be valid declarations of an integer variable?"
But one of the accepted answers is a constant: "final int x = 10;"
Could someone please explain what is the logic behind such answer?

Re: About Question enthuware.ocajp.i.v8.2.835 :

Posted: Sun Jun 10, 2018 11:52 am
by admin
It is correct because it is a valid declaration of an integer variable. Yes, it is a constant and "constant variable" sounds like an oxymoron but it is the right terminology nonetheless. x is not "variable" but it is "a variable".

Re: About Question enthuware.ocajp.i.v8.2.835 :

Posted: Tue Mar 01, 2022 1:38 am
by yuir12
Hello.

Am confused, can you please explain: access modifiers can only be used outside of constructors, methods, and initializers.... In other words, you cannot use var declarations while declaring class or instance fields.


Thanks

Re: About Question enthuware.ocajp.i.v8.2.835 :

Posted: Wed Mar 02, 2022 10:18 pm
by admin
You cannot use var declarations on instance or static fields.
class SomeClass{
var x =0; // not allowed
}