Question 117 / 297:  The following program fails to compile, where could possibly be the compilation error(s)?
Choose 2
class Creature {}

class Bird extends Creature {}

class Falcon extends Bird {}

public class Tester {

public static void main(String[] args) {

Creature c1 = new Creature();

Creature c2 = new Bird();

Bird b1 = (Bird) c1; // Line 1

Bird b2 = (Falcon) c2; // Line 2

Bird b3 = c2; // Line 3

Bird b4 = new Falcon(); // Line 4

Bird b5 = (Bird) new Creature(); // Line 5

Falcon f1 = b4; // Line 6

}

}

Oracle Certified Professional Java Programmer JavaChamp Team How to cast in java?
<< First < Previous Next > Last >>
Explanation:

Line 3 causes a compilation error because Type mismatch: cannot convert from Creature to Bird

Line 6 causes a compilation error because Type mismatch: cannot convert from Bird to Falcon

Exam Home Page
Ask
Edgar Delgado
Start Quiz
Marion Cabalfin
Start Test
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>