Question
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...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started