Tuesday, November 5, 2019
Reserved Words in Java
Reserved Words in Java Reserved words are words that cannot be used as object or variable names in a Java program because theyre already used by the syntax of the Java programming language. If you ttempt toà use any of the words below as identifiers in your Java programs, youll get an error like the one below. List of Reserved Java Keywords abstract assert boolean break byte case catch char class const continue default double do else enum extends false final finally float for goto if implements import instanceof int interface long native new null package private protected public return short static strictfp super switch synchronized this throw throws transient true try void volatile while *Theà strictfpà keyword was added to this list in Java Standard Edition version 1.2,à assertà in version 1.4, andà enumà in version 5.0. Even though goto and const are no longer used in the Java programming language, they still cannot be used as keywords. What Happens If You Use a Reserved Word? Lets say you try to create a new class and name it using a reserved word, like this: // you cant use finally as its a reserved word! class finally { à à à public static void main(String[] args) { à à à à à à //class code.. à à à } } Instead of compiling, the Java program will instead give the following error: expected
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.