In this third part of Java puzzlers, we will see a surprise in variable naming restrictions.
If I show you this, I'm sure you won't be surprised that this does not compile. static is one of the reserved keywords so why should it work?
Now I'll ask you a more difficult one. What you think about the below code.
Will this compile?
None of these should be reserved keyword. This is not C right?
If you thought that it will compile, you're wrong.
const and goto are reserved keywords, but bool and integer are fine.
If I show you this, I'm sure you won't be surprised that this does not compile. static is one of the reserved keywords so why should it work?
1 | public class Puzzler { |
2 |
3 | public static void main(String[] args){ |
4 |
5 | int static = 2 ; |
6 | } |
7 |
8 | } |
1 | public class Puzzler { |
2 |
3 | public static void main(String[] args){ |
4 | int bool = 0 ; |
5 | int integer = 1 ; |
6 | int const = 2 ; |
7 | int goto = 3 ; |
8 | } |
9 | } |
No comments:
Post a Comment