Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Animal ( public class Bird extends Animal t private static int numAnimals; protected String name; protected String sound; private int altitude; public Bird(String

image text in transcribed
public class Animal ( public class Bird extends Animal t private static int numAnimals; protected String name; protected String sound; private int altitude; public Bird(String n) f super(n, chirp") altitude se; public Animal(String n, string s) ( name n; sound s; numAnimals++; public void fly) f System.out.println("Bird "this.name +" is flying at altitude" altitude): public void breathe) ( System.out printin(name+is taking a breath"); ) public class Cat extends Animal f public Animal eat(Animal a) ( System.out.println("Animal "+nameis eating public Cat(String n) f animal: +a.name); super(n, "meow): return new Animal( "DeadAnimal", null); public void breathe)f public String getName )f System.out.printin(this.name is taking a super.breathe); return name; CAT breath): public String getsound)f return sound; public Bird eat(Bird b) ( System.out.printin("Cat this.name"is eating bird: "b.name); Bird db- new Bird("DeadBird"); db. sound null; return db; public static int getNumAnimalsOf return numAnimals; 4. What does the following main method output? public static void main (String l args) Animal a new Animal("Walrus", "aww aw") Bird b new Bird("Swallow") Cat c new Cat ("Tom") a.breathe ) b.breathe c.breathe ); System.out.println); b.fly) System.out.printin()2 Bird abby new Bird ("anotherEirdy") Animal di- b.eat (abby) Animal d2c.eat (b); System.out.printin(di.getName ()) System.out.printin (d2.getName ()) ?.getMumAnimals()); " animals: + systen, out.println ("Hun

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_2

Step: 3

blur-text-image_3

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

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions