Final Keyword Interview Questions in Java
What is the main difference between abstract method and final method?
Abstract methods must be overridden in sub class where as final methods can not be overridden in sub classWhen use final class in java ?
If a class needs some security and it should not participate in inheritance in this situation we need to use final class.Where you use final keyword in java ?
Final keyword in java are used at;- Final at method level
- Final at class level
- Final at variable level
What are final class, final method and final variable ?
- Final class: can not be extended.
- Final method: can not be overridden in the sub class.
- Final class: can not change it’s value once it is initialized.
What will happen if we try to extend final class in java ?
Compiler get an errorCan we declare interface as final ?
No, because interface must be implement in other class.What is final parameter?
If you declare any parameter as final, you cannot change the value of it.Can we declare constructor as final ?
No, constructor can't be final.What will happen if we try to override final methods in sub classes ?
Compile time error will come :Cannot override the final method from Super class, because you can't override final method in sub class.Can we create object for final class?
Yes we can create object for final class.Can we declare constructors as final?
No, constructors can not be final.Is it possible to declare final variables without initialization?
No. Its not possible to declare a final variable without initial value assigned.While declaring itself we need to initialize some value and that value can not be change at any time.
What is the use of final keyword in java ?
Final keyword in java is used to make any class or a method or a field as unchangeable. We can't extend final class, not override final method, can't change value of final variable.Can we change the value of an interface field ?
No, we can't change the value of an interface field. Because interface fields is by default final and static. They remain constant for whole execution of a program.What will happen if we try to override final methods in sub classes?
Compile time error will come :Cannot override the final method from Super classWhat is the actual use of final class in java?
If a class needs some security and it should not participate in inheritance in this scenario we need to use final class. We can not extend final class.Reference: Final Keyword Interview Questions
Enjoy your work feels so much lighter and get maximum results
ReplyDeleteObat Tradisional Penyakit Lepra Paling Mujarab
Obat Tradisional Trombus Otak Yang Paling Bagus
Cara Cepat Mengobati Tiroid Secara Tradisional
Obat Tradisional Tbc Paru Paru Yang Alami Dan Aman
Obat Tradisional Penyempitan Tulang Belakang Paling Mujarab
Cara Cepat Mengobati Radang Sendi Lutut, Tangan dan Kaki Secara Alami