Sunday, October 22, 2017

Java Interview Questions and Answers part -2

1. What is Class ?
     Class is a collection of objects, methods and constructors. It defined how an object will behave with different methods.

    syntax :

      class <class name>{
             
        fields;

        methods;

}


2. What is Object ?
     Object is a real time entity which keeps state and behavior. In java, object is an instance of a class.


3. What is JIT (Just-In-Time) compiler ?
     JIT impoves the performance of java application at run time.  It convert the bytecode into instructions for the processor hence it reduce the time needed for compilation.

4. What is final keyword ?
     Final keyword use with variables, methods and classes.
  • final variable value can not be changed.
  • final method can not be override.
  • final class can not inherit.

blank final variable : A final variable which has not any value at the time of variable declaration.


5. Can we override static method ?
     No, because static method always belongs to the same class in which it is declared.


6. Can there any abstract method without abstract class ?
    No, if there is any abstract method in the class, we have to make class as a abstract.


7. What is difference between throw and throws ?

     throws: It is used with method signature to declare the exception.

     throw : It is used to throw an exception explicitly. It is inside the method body.


           public void hellomesssge() throws IOException{
   
             throw new IOException("Not able to print hello")
         
}


8. What is the base class of Error and Exception ?

     Throwable.


9. What is Finally block ?
     finally block always with try block or try-catch block. When we need to execute the some code after occurred any exception then we used finally block.


10. What is Finalize ?
       finalize is a method to use cleanup the process. This method does not return any value. This method is always called by garbage collection thread.



                                                                                                              Read OOPs Concept
      

No comments:

Post a Comment