HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
1. Feel Free to ask and submit anything on and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.

corejava-keyword: difference between final and static keywords

could anyone please explain me the difference between final and static keywords and when they are used?

corejava x 353
keyword x 9
Posted On : 2015-06-03 23:18:07.0
profile Saksham Kumar - Saksham Kumar


I am going to tell you about where should we use static or where final. You will get the difference better...

there are three cases of final keyword where they are used:
-------------------------------------------------------------------------------------------------- variable: final is a keyword which is used to define constant in a program. The value of a variable will be constant.its value cant be change in the later part of a program. method: if the method is final then it cannot be overridden. class: final class can not generate their children or properties of a parent final class cannot be used by there child classes

static keyword can be used in the same three cases :
1.static variable
2.static method
3.static class

main is static that is the reason java program is run by a class name. Static things are free from covering class objects. Like if we define a variable as static in a class A then we can access that variable in same class directly. we don?t need to create object of class A to access it. If we want to access same variable in another class we can simply access it by class name instead of making object of class A.

Static method also can be called directly without using the object of covering class. static inner class also works like static method and same concept also apply on it.

Posted On : 2015-06-03 23:45:21
Satisfied : 1 Yes  0 No
profile Rishi Kumar - Rishi Kumar
Reply This Thread

Post Answer
Please Login First to Post Answer: Login login with facebook -