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?
About Question enthuware.ocajp.i.v8.2.835 :
Moderator: admin
-
- Posts: 1
- Joined: Sun Jun 10, 2018 11:38 am
-
- Site Admin
- Posts: 10043
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.835 :
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".
If you like our products and services, please help us by posting your review here.
-
- Posts: 22
- Joined: Thu Dec 09, 2021 11:23 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.835 :
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
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
-
- Site Admin
- Posts: 10043
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v8.2.835 :
You cannot use var declarations on instance or static fields.
class SomeClass{
var x =0; // not allowed
}
class SomeClass{
var x =0; // not allowed
}
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: Bing [Bot] and 39 guests