Question: Java SE classes are defined as shown below: class Shape { } class Quadrilateral extends Shape { } class Triangle extends Shape { } If

Java SE classes are defined as shown below:
class Shape {}
class Quadrilateral extends Shape {}
class Triangle extends Shape {}
If the variables below are declared:
Shape shape=new Quadrilateral{};
Quadrilateral quadrilateral= new Quadrilateral();
Which of the following statements are correct?
a. The statement Triangle tri=(Triangle)shape; will fail to compile
b. The statement Triangle tri =(Triangle)shape; will compile and execute without error
c. The statement shape=quadrilateral; will throw an exception at runtime
d. The statement Triangle tri =(Triangle) shape; will throw an exception at runtime.
e. The statement Triangle tri=(Triangle)quadrilateral; will fail to compile

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!