Exam Permalink:
https://www.jobilize.com/java-certification-questions
Question Permalink:
https://www.jobilize.com/how-to-cast-java-variables
Question 52 / 297:  Will the following code compile and if yes , what is the output?
interface Colorable {}

class Vehicle {}

class Car extends Vehicle implements Colorable {}

public class Tester {

public static void main(String[] args) {

Vehicle a = new Car();

Colorable i = (Colorable) a;

Vehicle b = new Vehicle();

Colorable j = (Colorable) b;

}

}

Oracle Certified Professional Java Programmer Yasser Ibrahim How to cast java variables?
A  The code compiles fine and produces no output
B  The code compiles fine but throws a RuntimeException because of the second casting
C  There is a compilation error because of the second casting
D  The code compiles fine but throws a RuntimeException because of the first casting
<< First < Previous Next > Last >>
Explanation:

The compiler doesn't object as long as the casting type is compatible with the declaration type

Exam Home Page
https://www.jobilize.com/java-certification-questions

Oracle Certified Professional Java Programmer

Author:

Access: Public Instant Grading

Ask
Nicole Bartels
Start Quiz
Dewey Compton
Start Exam
Madison Christian
Start Test
Yacoub Jayoghli
Start Quiz
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>