Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is the code for this in Java? Assignment Inheritance Learning Objectives Declare a subclass that derives from a superclas:s Demon Declare a variable of

What is the code for this in Java?

image text in transcribed

image text in transcribed

image text in transcribed

Assignment Inheritance Learning Objectives Declare a subclass that derives from a superclas:s Demon "Declare a variable of the superclass type and assign it an instance of the subclass type strate polymorphic behavior Access the public members of the superclass type Notice how the overridden versions of the subclass type are called Notice how the subclass specific members are inaccessible "Create an array of superclass type and use a foreach loop to iterate through it Style Comments On this and all upcoming assignments pay attention to style. Follow Java naming convention, use proper indentation group related code statements with single empty lines, use descriptive names etc. Strive to write code that is clear and easy to read Also: use doc comments on all your code Description: Write a program to demonstrate the use of inheritance and polymorphism. You will create 4 classes: Rectangle, Square, IsoscelesRightTriangle, and Circle In addition you will create a class called InheritanceApp. This class includes the main method. Here we test the four other classes and we demonstrate the polymorphic behavior Declare the classes as described below: Class Retangle: . Rectangle has 2 private final fields of type int: length and width It has (exactly) one parameterized constructor that initializes both fields It provides a getter (get accessor method) for each of the fields (no setter) It overrides the toString method so that it produces a result of the form Rectangle (lengthxwidth) e.g. Rectangle (5x4) Class Square: Square extends Rectangle No fields are declared in class Square It has a parameterized constructor with (only) one parameter The parameter is used to initialize both fields of Rectangle It has a method called getSide to expose the side-length of the square Override the toString method so that it will return a String of the following form Square (side) e.g. Square (4)

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions