Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

5 A4. Given the following class diagram, interfaces and classes that model various kinds of animals. What will be the errors in the main method?

image text in transcribed

5 A4. Given the following class diagram, interfaces and classes that model various kinds of animals. What will be the errors in the main method? For each error, indicate the line number of each incorrect statement and explain in one sentence why it is wrong. 1 2 3 interface Animal { int numberOf Legs(); } 4 interface Mammal extends Animal 6 > Animal numberOfLegs(: int 7 interface Reptile extends Animal {} 8 9 10 11 12 class Cat implements Mammal { public int number of Legs() { return 4; } } > Mammal > Reptile 14 18 class Tiger extends Cat { } A A 16 17 18 1 1 Cat +numberOfLegs(): int class Snake implements Reptile { public int number of Legs() { return 0; 3 ) 19 20 Snake +numberOfLegs(): int K 21 Tiger 1 public class Animals { public static void main(String[] args) { Animal animali, animal2, animal3; Mammal mammall; Cat cat1; Snake snake1; Tiger tigeri; List listi, list2; 10 11 12 13 14 animalt - neu Tiger(); snake 1 - new Animal(); animal2 = new Animal(); cat1 = new Tiger(); mammal1 = new Snake(); tiger1 - mammall; anima13 - cati; list1 = new ArrayList(); list 2 -new ArrayList(); 16 17 IN } 19 20 3

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