Questions and Answers
Which of the following statements about casting are true?
Both interface and class references can be cast to either type.
What is the correct statement about interface casting?
An interface reference cannot be cast to another interface type.
What is true about class casting in Java?
A class reference cannot be cast to the interface type.
Study Notes
Casting in Java
- Casting is a process of converting one data type into another
- There are two types: primitive casting and reference casting
Interface Casting
- Interface casting allows casting an object to an interface type
- This is possible because an object may implement multiple interfaces
Class Casting
- Class casting allows casting an object to a class type
- This is possible because an object has a unique class type
- In Java, you can cast a subclass to its superclass but not vice versa
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.