Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This lab provides the superclass called Animal and the driver called TestInheritance (which contains main where the program starts). Your job is to add a

This lab provides the superclass called Animal and the driver called TestInheritance (which contains main where the program starts). Your job is to add a new subclass called Dog which uses the superclass Animals Name through inheritance (by using the keyword extends) and adds the breed in the Dog subclass. You add this new subclass Dog to the template provided after the following line: "//add subclass Dog using Inheritance after this line" Do not make any other changes to the code in the template. So all animals have a name as defined in the superclass Animal but dogs also have a breed as defined in the subclass Dog. You should review Zybooks Chapter 10 available subsections on Inheritance prior to attempting this lab. There is no input data from the user to run this program.

//this is the superclass class Animal { private String name; public void setName (String n) { name = n; } public String getName() { return name; } }

//add subclass Dog using inheritance after this line

//this is the driver where the program starts public class TestInheritance { public static void main(String[] args) { Dog dg = new Dog(); Dog dg1 = new Dog(); dg.setName("Lassie"); dg.setBreed("collie"); dg1.setName("Benji"); dg1.setBreed("mixed"); System.out.println("Dog Name: " + dg.getName()); System.out.println("Dog Breed: " + dg.getBreed()); System.out.println("Dog Name: " + dg1.getName()); System.out.println("Dog Breed: " + dg1.getBreed()); } }

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

Question

5-8 What are the advantages and disadvantages of the BYOD movement?

Answered: 1 week ago