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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
walltearer
Posts: 1
Joined: Sun Jun 10, 2018 11:38 am

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

Post 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?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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".
If you like our products and services, please help us by posting your review here.

yuir12
Posts: 22
Joined: Thu Dec 09, 2021 11:23 pm
Contact:

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

Post 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

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

You cannot use var declarations on instance or static fields.
class SomeClass{
var x =0; // not allowed
}
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 48 guests