Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given the code below, answer the following: 1. (+1) In statement 1, which Java rule allows us to use a reference of a type different

image text in transcribed
image text in transcribed
Given the code below, answer the following: 1. (+1) In statement 1, which Java rule allows us to use a reference of a type different from the object type? 2. [+2] In statement 1, trace the chain of constructors being called by Chicken(50), i.e. list all constructors from all classes that were called by this statement and indicated their order of execution and what each constructor does. Make sure to refer to how super is used in this process. 3. [+2] In statement 2, write the expected output and explain how dynamic binding works to produce that output. public class Test public static void main(String[] args) { Displayable d = new Chicken(50); //1 d.display(); 1/2 3 1 public interface Displayable{ void display(); public abstract class Animal implements Displayable { private int x,y; public Animal(){X-8; y=6;} public Aninal(int x, int y) {this.x = x; this.y = y;} 3. [+2) In statement 2, write the expected output and explain how dynamic binding works to produce that output public class Test public static void main(Strinel] args) { Displayable d = new Chicken(50); // d.display(); 1/2 1 public interface Displayable void display(); } public abstract class Animal implements Displayable { private int x, y: public Animal(){x=8; y=8;) public Animal (int x, int y){this.x = x; this.y = y;) public class Bird extends Animal private int weight; public void displayO{System.out.println("Bird");} } public class Chicken extends Bird private int energy public Chicken(int energy){this.energy = energy;) }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions