Hello Friends, In this Blog Post I am going to let you know about a few more interview questions of core java related to Polymorphism.
Core java interview questions covers all the important questions of the topics mentioned above.
These core java interview questions is a great help to remember all the important highlights and important topics from each java chapter.
These interview questions will surely help to understand a few very confusing concepts in java.
What is coercion?
coercion is the automatic conversion between different data types done by a compiler.
What is conversion?
Conversion is the explicit change in the data type specified by the cast operator.
What is method signature?
Method signature represents the method name along with method parameters.
What is method overloading?
Writing two or more methods in the same class in such a way that each method has the same name but with a different method, a signature is called method overloading.
What is method overriding?
Writing two or more methods in super and subclass such that the methods have the same name and the same signature is called method overriding.
What is the difference between method overloading and method overriding?
The difference between method overloading and method overriding is given below.
Writing two or more methods with the same name but with different signature is called method overloading.
Writing two or more methods with the same name and same signature is called method overriding.
Method overloading is done in the same class.
Method overriding is done in super and subclass.
In method overloading, the method return type can be same or different.
In method overriding, the method return type should also be the same.
JVM decides which method is called depending on difference in method signature.
JVM decide which method is called depending on the data type(class) of the object used to call the method.
Method overloading is done when the programmer wants to extend the already available feature.
Method overriding is done when the programmer wants to provide a different implementation(body) for the same feature.
Method overloading is code refinement. The same method is refined to perform a different task.
Method overriding is code replacement. The sub class method overrides(replaces) the super class method.
Can you override private method?
No, private methods are not available in the subclasses, so they can not be overridden.
Can we take a private methods and final methods as same?
Yes, the java compiler assigns the value for the private methods at the time of compilation. Also, private methods can not be modified at run time. This is the same case with the final methods also.
Neither the private methods nor the final methods can be overridden. So, private methods can be taken as the final methods.
What is final?
‘final’ keyword is used in two ways:
It is used to declare the constants, as :
final double PI = 3.14159; //PI is constant.
It is used to prevent inheritance, as :
final class A // Subclass to A cannot be created.
What is the difference between dynamic polymorphism and static polymorphism?
Dynamic polymorphism is the polymorphism exhibited at runtime. Here, the java compiler does not understand which method is called at compilation time. Only JVM decides which method is called at runtime. Method overloading and method overriding using instance methods are examples of dynamic polymorphism.
Static polymorphism is the polymorphism exhibited at compile time. Here, the java compiler knows which method is called. Method overloading and method overriding using static methods; method overriding using the private or final method are examples for static polymorphism.
So this was all about the Core java interview questions in this topic.
These Core java interview questions could be a great help in your college viva, academic study, and any job interview.
In the case of any queries, you can write to us at [email protected] we will get back to you ASAP.
Hope! you would have enjoyed this post about Core Java Interview Questions Part 11/Polymorphism.
Please feel free to give your important feedbacks in the comment section below.
Have a great time!