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.
invalid answer enthuware.ocajp.i.v7.2.1022
Moderator: admin
-
- Posts: 6
- Joined: Mon Jun 29, 2015 8:41 pm
- Contact:
-
- Site Admin
- Posts: 10386
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: invalid answer enthuware.ocajp.i.v7.2.1022
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.
Having said that, the given question and the answer are not invalid. The given code is perfectly legal.
HTH,
Paul.
-
- Posts: 6
- Joined: Mon Jun 29, 2015 8:41 pm
- Contact:
Re: invalid answer enthuware.ocajp.i.v7.2.1022
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.
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.
-
- Site Admin
- Posts: 10386
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: invalid answer enthuware.ocajp.i.v7.2.1022
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.jayallenloew wrote:Well alright, technically speaking, false, true, and null are not listed on the Oracle site as keywords either.
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.But we are expected to realize they must never be used as the names of our variables in the Java language.
Whether it is a good thing or a bad thing is a separate discussion.
-
- Posts: 1
- Joined: Sun Jan 27, 2019 2:40 am
- Contact:
Re: invalid answer enthuware.ocajp.i.v7.2.1022
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.
The error is: "Uncompilable source code - variable Integer might not have been initialized"
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");
}
-
- Site Admin
- Posts: 10386
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: invalid answer enthuware.ocajp.i.v7.2.1022
Interesting example indeed, DmitryM!
Who is online
Users browsing this forum: No registered users and 8 guests