Oracle Java Interview Questions & Answers Set-3

«« Previous
Next »»

41) Can we override static method?
Ans: No, you can't override the static method because they are the part of class not object.

42) Why we cannot override static method?
Ans: It is because the static method is the part of class and it is bound with class whereas instance method is bound with object and static gets memory in class area and instance gets memory in heap.

43) Can we override the overloaded method?
Ans: Yes.

44) Difference between method Overloading and Overriding.

Method Overloading
Method Overriding
1) Method overloading increases the readability of the program. Method overriding provides the specific implementation of the method that is already provided by its super class.
2) method overlaoding is occurs within the class. Method overriding occurs in two classes that have IS-A relationship.
3) In this case, parameter must be different. In this case, parameter must be same. 

45) Can you have virtual functions in Java?
Ans: Yes, all functions in Java are virtual by default.

46) What is covariant return type?
Ans: Now, since java5, it is possible to override any method by changing the return type if the return type of the subclass overriding method is subclass type. It is known as covariant return type.

Core Java - OOPs Concepts: final keyword Interview Questions

47) What is final variable?
Ans: If you make any variable as final, you cannot change the value of final variable(It will be constant).

48) What is final method?
Ans: Final methods can't be overriden. 

49) What is final class?
Ans: Final class can't be inherited.

50) What is blank final variable?
Ans: A final variable, not initalized at the time of declaration, is known as blank final variable.

51) Can we intialize blank final variable?
Ans: Yes, only in constructor if it is non-static. If it is static blank final variable, it can be initialized only in the static block.

52) Can you declare the main method as final?
Ans: Yes, such as, public static final void main(String[] args){}.

Core Java - OOPs : Polymorphism Interview Questions

53) What is Runtime Polymorphism?
Ans: Runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time.

In this process, an overridden method is called through the reference variable of a super class. The determination of the method to be called is based on the object being referred to by the reference variable.

54) Can you achieve Runtime Polymorphism by data members?
Ans: No.

55) What is the difference between static binding and dynamic binding?
Ans: In case of static binding type of object is determined at compile time whereas in dynamic binding type of object is determined at runtime.

Core Java - OOPs Concepts : Abstraction Interview Questions

56) What is abstraction?
Ans: Abstraction is a process of hiding the implementation details and showing only functionality to the user.

Abstraction lets you focus on what the object does instead of how it does it.

57) What is the difference between abstraction and encapsulation?
Ans: Abstraction hides the implementation details whereas encapsulation wraps code and data into a single unit.

58) What is abstract class?
Ans: A class that is declared as abstract is known as abstract class. It needs to be extended and its method implemented. It cannot be instantiated.

59) Can there be any abstract method without abstract class?
Ans: No, if there is any abstract method in a class, that class must be abstract.

60) Can you use abstract and final both with a method?
Ans: No, because abstract method needs to be overridden whereas you can't override final method.

«« Previous
Next »»