Exam Permalink:
https://www.jobilize.com/java-certification-questions
Question Permalink:
https://www.jobilize.com/when-java-classcastexception-is-thrown
Question 115 / 297:  Which statement(s), inserted independently at // insert code here, will compile?
Choose 3
class Creature {

String getName() {

return "Creature";

}

}

class Bird extends Creature {

String getName() {

return "Bird";

}

}

class Falcon extends Bird {

String getName() {

return "Falcon";

}

}

public class Tester {

public static Bird getIt(Creature c) {

System.out.println(c.getName());

return (Bird) c;

}

public static void main(String[] args) {

// insert code here

}

}

Oracle Certified Professional Java Programmer Yasser Ibrahim When java classCastException is thrown?
<< First < Previous Next > Last >>
Explanation:

The code will compile fine when inserting the first three statements. But will throw a classCastException at run time for statement getIt(new Creature()); , because the casting then will fail.

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

Oracle Certified Professional Java Programmer

Author:

Access: Public Instant Grading

Ask
Sarah Warren
Start Test
Keyaira Braxton
Start Exam
Yacoub Jayoghli
Start Quiz
Lakeima Roberts
Start Quiz
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>