Core Java - Interview Questions and Answers for 'Final' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Newest

   
 Q41. What is the use of final keyword ?Core Java
Ans. final keyword is a modifier that means differently when applied to variables, methods and classes.

1. Final variable cannot be changed once initialized
2. Final method cannot be overridden
3. Final class cannot be sub classed

  Sample Code for final variable

  Sample Code for final method

  Sample Code for final class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     final  final keyword     Asked in 1 Companies      Basic        frequent


 Q42. How do we define constant variables in Java ?Core Java
Ans. By using static and final modifiers.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     constant variables   static final      basic        frequent


 Q43. Will the following code compile ?

final HashMap hm = new HashMap();
hm.put("Ravi", 221);
Core Java
Ans. Yes, it will compile without error. final in this context means that the reference hm cannot be assigned to a new hash map but didn't restrict from changing the state of collection already held by hm.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     final  final variable     Asked in 1 Companies


 Q44. What is the difference between being final and being immutable ? Are string final or immutable in Java ?Core Java
Ans. Being final in the sense of objects or object reference means that the reference cannot be reassigned to a different object whereas being immutable means that the object contents cannot be changed.

Strings in Java are immutable.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     string  immutable  immutability  final vs immutable  immutability


 Q45. How different is it when final applied to variables and object references ? Core Java
Ans. final when assigned to object references doesn't make them immutable. It means that the references cannot be de-referenced.

final when applied to variables means that the value cannot be changed.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     final keyword  final variable


 Q46. What will the following code print and Why

class Class1 {
static{
System.out.println("Wow");
}
public static final int xyz=1;
}

class Class2{
public static void main(String[] args) {
System.out.println(String.valueOf(Class1.xyz));
}
}
Core Java
Ans. 1

Reason being that Class1.xyz is replaced with 1 during pre compilation only and a reference to Class1 is never made.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     static final   pre compilation


 Q47. What will happen if there is an exception in Java finally block ?Core Java
Ans. The regular behavior of exception handling will occur. It will look for any immediate catch handler and if none is provided, it would be transmitted to the callers until a catch handler is found or it's out of main function.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     exceptions  finally


 Q48. Why Java has final class ?Core Java
 This question was recently asked at 'Avis'.This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     final class   final keyword     Asked in 1 Companies      basic


 Q49. Are final methods faster than regular instance methods ?Core Java
Ans. Yes. As they cannot be overridden , there is no use of virtual table concept which is used for dynamic binding resolution.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     final methods   final keyword      expert


 Q50. Can constructors be final ?Core Java
Ans. No. They are never inherited and therefore are not subject to hiding or overriding.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     constructor  final  final constructor     Asked in 1 Companies


 Q51. If we have a return statement inside the finally block, Then what will happen ?Core Java
Ans. Returning from inside a finally block will cause exceptions to be lost. A return statement inside a finally block will cause any exception that might be thrown in the try block to be discarded.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     exception handling  finally block     Asked in 1 Companies


 Q52. Which of the following methods are used by Java Garbage Collection Mechanism ?Core Java
a. final
b. finally
c. finalize
d. All of the above

Ans.c. finalize

 Q53. In which case finally won't get executed ?Core Java
a. in case of exception
b. in case of normal execution
c. in case of return statement before end of try block
d. in case of force program termination

Ans.d. in case of force program termination

 Q54. Which of the following class cannot be extended or inherited ?

StringBuffer , StringBuilder
Core Java
a. StringBuffer
b. StringBuilder
c. Both cannot be extended
d. Both can be extended

Ans.c. Both cannot be extended

previous 30   

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: