Using this Java program. Use the Java hierarchy below and add one overriding method and one overloading.
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 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(); } }
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch