Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following class definition: publia class Animal publie void greeting) System.out.println(Hello! ): publie class Cat extends Animal ( eoverride public void greeting() { System.

image text in transcribed
Consider the following class definition: publia class Animal publie void greeting) System.out.println("Hello! ): publie class Cat extends Animal ( eoverride public void greeting() { System. out . printin ("Meow! publie elass Dog extends Animal aoverride public void greeting System.out.println("Woof! public class BigDog extends Dog ( override public void greeting System.out.print1n ("Woow! 1. (4 pts) Given the definition: Animal anlnew BigDog ) Animal an2 new Animal) BigDog dognew BigDog ) Judge the following assignments are legal or illegal. an2 = dog; . dog = anl ; . dog= (BigDog ) an2 ; . if (anl instanceof BigDog) dog (BigDog) anl; = 2. (6 pts) Find out the outputs for the following program public class TestAnimal ( public static void main(Stringi] args) ( Animal animal 1 = new Cat(); animall.greeting ): Animal animal 2 new Dog(); anima12.greeting): Animal animal 3 new BigDog(); anima13.greeting)

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

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

ISBN: 1583474013, 978-1583474013

Students also viewed these Databases questions