Exam Permalink:
https://www.jobilize.com/java-certification-questions
Question Permalink:
https://www.jobilize.com/casting-rules-in-java
Question 118 / 297:  What inserted, independently at // insert code here , will compile?
Choose 3
class Creature {

void grow() {

}

}

class Bird extends Creature {

void fly() {

}

}

class Falcon extends Bird {

void hunt() {

}

}

public class Tester {

public static void main(String[] args) {

Creature c1 = new Bird();

Falcon c2 = new Falcon();

// insert code here

}

}

Oracle Certified Professional Java Programmer Yasser Ibrahim Casting rules in java
<< First < Previous Next > Last >>
Explanation:

Pay attention to what question is asking about, it asks whether the code will "compile" with no error, not if it will "run" with no error.

The first and third options will compile and run fine.

The fourth option will compile fine, but will throw ClassCastException at run time

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

Oracle Certified Professional Java Programmer

Author:

Access: Public Instant Grading

Ask
Dewey Compton
Start Exam
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>