What is final keyword in JAVA-hindi ?-vishmy1.blogspot.com

final keyword in JAVA 

final:- constant variable must be declared and initialized in the same statementsThe word-final is a JAVA keyword, for declaring a constant value. The only difference between a normal variable and a final variable is that we can reassign value to a normal variable but we can't change the value of a final variable once assign. hence final variable must be used only when you want a variable to be constant.

final: - एक constant variable को एक ही statements में घोषित और शुरू किया जाना चाहिए। constant value घोषित करने के लिए शब्द-फाइनल(final) एक JAVA keyword है। एक  normal variable और final variableके बीच एकमात्र अंतर यह है कि हम एक सामान्य चर के लिए मान को पुन: असाइन कर सकते हैं लेकिन हम एक बार असाइन किए गए final variable के मूल्य को बदल नहीं सकते हैं। इसलिए अंतिम चर का उपयोग केवल तभी किया जाना चाहिए जब आप एक चर को स्थिर रखना चाहते हैं।

The final keyword in JAVA is used to restrict the user.

JAVA में final keyword का उपयोग user को restrict करने के लिए किया जाता है।

final can be a variable, a method, and a class, the final keyword can be applied with the variable

final एक चर, एक विधि और एक वर्ग हो सकता है, final कीवर्ड चर के साथ लागू किया जा सकता है।

A final variable that has no value is called a blank final variable or an uninitialized variable. it can be initialized in the constructor only.

एक final चर जिसका कोई मूल्य नहीं है उसे एक blank final variable या एक असमान परिवर्तनशील चर कहा जाता है। इसे केवल कंस्ट्रक्टर में शुरू किया जा सकता है।


What is final keyword in JAVA-hindi ?-vishmy1.blogspot.com


1 )- final variable:-  when a variable declared with final keyword, then it is called a final variable. final variable means that the value which we are assigned into a final variable can not be changed, the value of the final variable remains constant throughout the execution of the program.

1 )- final variable: - जब कोई variable, final keyword के साथ घोषित किया जाता है, तो उसे  final variable कहा जाता है।  final variable का अर्थ है कि जो मूल्य हमें अंतिम चर में सौंपा गया है उसे बदला नहीं जा सकता है, अंतिम चर का मान program के execution के दौरान स्थिर रहता है।

1 )- How to create final variable:-

final int a = 10;

final int a; //blank final variable

ex:-

class test
{
    public static void main(String args[])
    {
           final int a = 10;
           System.out.println(i);
     }
}


2 )- final method:- The method that is declared with the final keyword is called a final method. A final method can not be overridden. if we override a final method then, it will throw a compile-time error.

2 )- final method:- final कीवर्ड के साथ घोषित method को final method कहा जाता है। एक final method को ओवरराइड नहीं किया जा सकता है। यदि हम एक final method को ओवरराइड करते हैं, तो यह एक compile-time error को फेंक देगा।



 how to declare a final method:-

Syntax:- 

final void method_name()
{
   statement;
}

ex:-

class test
{
      final void m1()
      {
           System.out.println("this is a final method :");
       }
 }
class test1 extends test
{
      void m2()
       {
            //compile-time error.
           System.out.println("this is illegal:");
       }
}
           

3 )- final class:- when a class declared with the final keyword then it is called a final class. A final class can not be inherited. final keyword is used with the class to prevent the inheritance. if we inherit a final class then it will throw a compile-time error.

3 )- final class:- जब किसी क्लास को फाइनल कीवर्ड के साथ घोषित किया जाता है तो उसे फाइनल क्लास कहा जाता है। एक अंतिम वर्ग को विरासत( inherited) में नहीं दिया जा सकता है। वंशानुक्रम(inherit) को रोकने के लिए वर्ग के साथ final कीवर्ड का उपयोग किया जाता है। अगर हमें एक final वर्ग विरासत( inheritance) में मिलता है, तो यह एक compile-time error को फेंक देगा।

how to declare a final class:-

Syntax:-

final class class_name

ex:-

final class test
{
    //fields & methods
}
class test1 extends test
{
    compile-time error
}


Note:- In the next blog I'm going to explain about static keyword in JAVA.

please write a comment if you find anything incorrect in this blog, and if you like it then share it with your friends also and subscribe for more blogs.










Post a Comment

0 Comments