WHAT IS FINAL KEYWORD ?

THE FINAL KEYWORD CAN BE USED BEFORE A CLASS, METHOD, VARIABLE
Final Classes When used in a class declaration, -the final keyword before class means the class can't be subclassed. In other words, no other class can ever extend (inherit from) a final class, and any attempts to do so will give you a compiler error.
For example, the String class cannot be subclassed because it is final

Final method- the final keyword before a method means we can not override the method.

Final variable
- the final keyword before a variable means it becomes a constant and the value can not be changed further.

11 comments:

  1. what is the difference between final,finally,finalize?

    ReplyDelete
  2. what is the advantage of abstract classes in java?

    ReplyDelete
  3. by defining an abstract class java hand overs the method implementation to the program developer, JAVA knows that that method will be there but it does not know its body,
    by defining abstract class the class marks the methods abstract whose body is unknown but it also defines method body which is known,Both options are there,
    suppose there is a class animal. we know animal can not talk. it is same for all.but number of legs is different. So wee have make an abstract method getLegs() which will have no body but the method lives() is same for all animal. So it will have body. When the subclass(can be dog,can be a bird) no need to define the method lives() because it is already defined in the super class, but we have to override the method getLegs() for dog and for crow also because it is different for both.
    Here see the abstract class knows there must be a method getLegs() but i does not know its implementation,

    ReplyDelete
  4. @USHA
    These three final,finally and finalize are three completely different concepts,
    Does it sound good if i will ask what is the difference between a table and a computer?
    you can check the post what they are,
    Anyway remember final is a keyword, finally defines a block and finalize is a method,

    ReplyDelete
  5. static{}
    what is the meaning of above block and what it does?

    ReplyDelete
  6. Static {} is a block that is executed before main method.It is executed at run time through JVM.Static block never used this,super keywords.

    ReplyDelete
  7. Abstract is a keyword.
    If u declare a class through this keyword,then
    1.You can't instantiate it.means u can't creat its object.
    2.It must be inherited.
    3.Constructor of abstract class is never called.It must be called through super keyword.
    4.Abstract methods must be declared in abstract classes.
    5.An abstract class may or mayn't contain abstract methods.
    Abstract method:
    It does not have a body .It is declared through abstract keyword.It must be overridden in the child classes.

    ReplyDelete
  8. Advantage of abstract class:
    At first it supports Polymorphism.
    U a declare an abstract class .With some methods and later on keep on use it by inheriting it and do according to your demand.

    ReplyDelete
  9. Thanks regarding delivering this type of awesome post
    شركة طيور الجنة افضل شركة تنظيف بالدمام شركة متخصصة فى تنظيف المنازل بالدمام والخبر حيث لدينا طرق خاصة عن باقى شركات التنظيف وعندنا افضل عمال التنظيف حيث انهم متخصصون فى اعمال النظافة حيث اننا نعمل على رضاء العميل حيث نعطية مايرضية من اعمل التنظيف فنحن شركة تنظيف فلل بالدمام والخبر نتخصص فى نظافة الفلل بالدمام فتنظيف الفلة من الاعلى الى الاسفل حتى الحوش ونقوم ايضا كــ شركة تنظيف شقق بالدمام والخبر بنظافة الشقة من ارضيات وجدران وحمامات ومطابخ فهناك اشكال مختلفة من الشقق بالدمام ولكن الشقة التى نقوم بتنظيفها لابد وان تكون مختلفة فشركة طيور الجنة تعطيك ما يرضيك ولدينا كــ شركة تنظيف منازل بالدمام افضل طرق نظافة المنازل بالدمام والخبر وهناك شركة تنظيف موكيت بالدمام والخبر حيث اننا نقوم بغسيل الموكيت بافضل طرق التنظيف وافضل ماكينات التنظيف وهذا ما يميز شركتنا عن باقى شركات الرياض لاننا افضل شركة تنظيف بالخبر والخبر وعندنا تجد شركة تنظيف مجالس بالدمام والخبر حيث غسيل المجالس بطرقنا الخاصة ولدينا فرع شركة تنظيف كنب بالدمام ونقدم لكم فرع شركة جلى بلاط بالدمام للقيام بخدمات الجلى

    ReplyDelete
  10. Al Harthy is the company of the best companies in Riyadh cleaning homes, apartments and villas cleaner and washing boards and we have Harthy branch company to transport furniture and luggage store and a branch in Riyadh in Riyadh combat insects and wiring sewage company ,
    The company offers its services as follows :
    شركة جلى بلاط بالرياض
    شركة مكافحة الصراصير بالرياض
    شركة مكافحة الفئران بالرياض
    شركة النمل الابيض بالرياض
    شركة مكافحة الوزغ بالرياض
    شركة مكافحة بق الفراش بالرياض
    شركة نقل اثاث من الرياض الى جدة
    شركة نقل اثاث خارج الرياض

    ReplyDelete