invalid answer enthuware.ocajp.i.v7.2.1022

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

Moderator: admin

Post Reply
jayallenloew
Posts: 6
Joined: Mon Jun 29, 2015 8:41 pm
Contact:

invalid answer enthuware.ocajp.i.v7.2.1022

Post by jayallenloew »

RE: enthuware.ocajp.i.v7.2.1022

Don't ever -- ever -- use a Java keyword as your variable name. This is an incredibly foolish thing to do.

Don't ever do this in your code regardless of what this exam says or what the compiler allows.

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

Re: invalid answer enthuware.ocajp.i.v7.2.1022

Post by admin »

While what you are saying is indeed correct advice, please note that String is not a Java keyword.
Having said that, the given question and the answer are not invalid. The given code is perfectly legal.

HTH,
Paul.

jayallenloew
Posts: 6
Joined: Mon Jun 29, 2015 8:41 pm
Contact:

Re: invalid answer enthuware.ocajp.i.v7.2.1022

Post by jayallenloew »

Well alright, technically speaking, false, true, and null are not listed on the Oracle site as keywords either.

But we are expected to realize they must never be used as the names of our variables in the Java language.

Frankly, this is like a man saying he figured out a way to drive ninety through a school zone and not get stopped. It's just something that should never be attempted.

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

Re: invalid answer enthuware.ocajp.i.v7.2.1022

Post by admin »

jayallenloew wrote:Well alright, technically speaking, false, true, and null are not listed on the Oracle site as keywords either.
true, false, and null are literals. String is not that either. That is the whole point of the question. The name String has no special meaning for Java language.
But we are expected to realize they must never be used as the names of our variables in the Java language.
Again, this is a valid point but not much relevant for the exam. The exam is more focused on legality of constructs and less on practical aspects.
Whether it is a good thing or a bad thing is a separate discussion.

DmitryM
Posts: 1
Joined: Sun Jan 27, 2019 2:40 am
Contact:

Re: invalid answer enthuware.ocajp.i.v7.2.1022

Post by DmitryM »

Another crazy example of using a class name for a reference variable. Based on the previous question I thought it would compile.
But it would not! The reason is the right side Integer refers to the Integer
variable, not the class name. And it was not initialized in the local block.

Code: Select all

    public static void main(String[] args) {        
        Integer Integer = Integer.parseInt("10");                                
    }
The error is: "Uncompilable source code - variable Integer might not have been initialized"

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

Re: invalid answer enthuware.ocajp.i.v7.2.1022

Post by admin »

Interesting example indeed, DmitryM!

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests