Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using this Java program. Use the Java hierarchy below and add one overriding method and one overloading. The main method should create an instance of

Using this Java program. Use the Java hierarchy below and add one overriding method and one overloading. The main method should create an instance of the class and demonstrate the correct functionality of the overriding and overloading methods. class Ducati extends Motorcycles { // attributes float MilesPerGallon;

// constructor Ducati(int horsepower,float FrontTireSize,float RearTireSize,float MilesPerGallon) { super(horsepower,FrontTireSize,RearTireSize); this.MilesPerGallon=MilesPerGallon; } public void zooming(){ System.out.println("Ducati's are the fastest coming in at 185mph and Zoom"); } }

class Harley extends Motorcycles { // attributes float width; float length;

// constructor Harley(int horsepower,float FrontTireSize,float RearTireSize,float width,float length) { super(horsepower,FrontTireSize,RearTireSize); this.width=width; this.length=length; }

public void cruising(){ System.out.println("Harley's are slower coming arouind 115mph and meant for cuising"); } } class Motorcycles { // attributes int horsepower; float FrontTireSize; float RearTireSize;

// constructor Motorcycles(int horsepower,float FrontTireSize,float RearTireSize) { this.horsepower=horsepower; this.FrontTireSize=FrontTireSize; this.RearTireSize=RearTireSize; } public void drive() { System.out.println("===Motorcyles==="); } }

import java.util.Scanner;

public class test {

public static void main(String[] args) { Scanner sc=new Scanner(System.in); // creating instance of child classes

Harley Harley=new Harley(100,160,240, 30, 94); Harley.cruising(); Harley.drive();

Ducati Ducati=new Ducati(221, 120, 200, 30); Ducati.drive(); Ducati.zooming();

sc.close(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

java import javautilScanner class Motorcycles int horsepower float frontTireSize float rearTireSize Motorcyclesint horsepower float frontTireSize float rearTireSize thishorsepower horsepower thisfront... 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

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

Students also viewed these Programming questions

Question

What are the roles played in effective delegation?

Answered: 1 week ago

Question

Q Describe the superheating process?

Answered: 1 week ago

Question

Show that . Give an interpretation involving subsets.

Answered: 1 week ago