Skip to content

Instantly share code, notes, and snippets.

@arsalankhan994
Created December 30, 2021 12:40
Show Gist options
  • Save arsalankhan994/9521ec87c28a706bd031fc6ded979196 to your computer and use it in GitHub Desktop.
Save arsalankhan994/9521ec87c28a706bd031fc6ded979196 to your computer and use it in GitHub Desktop.
public class KeywordsJava {
public static void main(String[] args) {
/*
using final, to assign value only one time
*/
final String nonChangeableVariable = "Erselan Khan";
nonChangeableVariable = "Arsalan Khan";
/*
Accessing object bound method
*/
SomeClass someClass = new SomeClass();
someClass.objectBoundMethod();
/*
using static keyword, for accessing class bound method
*/
SomeClass.classBoundMethod();
try {
String name = null;
name.toString(); // this line will throw null pointer exception
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("finally called");
}
}
}
class SomeClass {
static void classBoundMethod() {
System.out.println("This is class bound method");
}
void objectBoundMethod() {
System.out.println("This is object bound method");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment