VOOZH about

URL: https://www.javacodegeeks.com/2020/05/java-puzzlers-from-oca-part-3.html

⇱ Java puzzlers from OCA part 3 - Java Code Geeks


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?

public class Puzzler {

 public static void main(String[] args){

 int static = 2;
 }

}

Now I’ll ask you a more difficult one. What you think about the below code. Will this compile?

public class Puzzler {

 public static void main(String[] args){
 int bool = 0;
 int integer = 1;
 int const = 2;
 int goto = 3;
 }
}

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.

Published on Java Code Geeks with permission by Sezin Karli, partner at our JCG program. See the original article here: java puzzlers from oca part 3

Opinions expressed by Java Code Geeks contributors are their own.

Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

👁 Photo of Sezin Karli
Sezin Karli
May 5th, 2020Last Updated: May 4th, 2020
0 134 1 minute read

Sezin Karli

Mathematics Engineer & Computer Scientist with a passion for software development. Avid learner for new technologies. Currently working as Senior Software Engineer at Sahibinden.com.
Subscribe

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Back to top button
Close
wpDiscuz