Note: Explanation is given avoiding more buzz words. Easily understandable manner.
- What is casting?
Converting one data type (or object) to the other is known as casting. It is required in a programming language as the user entered data may be in different form than required in coding.
- How many types of casting exists in Java?
There are two types of casting – Primitive data type casting and Object casting (string to data type conversion is not casting).
- How many types of primitive data type casting exist in Java?
Three types – implicit casting, explicit casting and boolean casting.
- How many types of object casting exist in Java?
Two types – implicit casting and explicit casting.
- What are data type casting rules?
1. A data type of lower size (occupying less memory) can be assigned to a data type of higher size implicilty (done by JVM automatically).
2. But the converiosn of data type of higher size to lower size requires explicit conversion (should be done by programmer himself).
- What are object casting rules?
1. Object of the same class can be assigned to one another and is done implicilty.
2. A subclass object can be assigned to a super class object and is done implicitly.
3. A super class object cannot be assigned to a subclass object, and still to do, requires explicit casting.
- What is dynamic method dispatch or dynamic binding?
Decision of which method is to be sent for execution at runtime is known as dynamic method dispatch or dynamic binding (remember, Java achieves static binding through method overloading).
- How Java achieves dynamic polymorphism?
Java achieves dynamic polymorphism through method overriding and object casting.
Object Casting Polymorphism Interview Questions
Pass your comments on suggestions on this tutorial on "Object Casting Polymorphism Interview Questions" to improve the quality.