Computer Science, asked by sudeshna8ghosh, 4 months ago

Write a program that creates a base class called “Distance”. It stores the distance between two points in a double value variable and contain an abstract method called travelTime() that outputs the time it takes to travel that distance, assuming that the distance is in miles and speed is 60 miles per hour. In derived class called “DistMKS”, override travelTime() assuming that distance is in Kilometers and speed is 100 kilometers per hour(Use base class Reference to call a function).

using java​

Answers

Answered by badboy07731
3

Answer:

Hope it helps, mark me brainliest

Follow me on Brainly, so whenever you ask questions, I can answer instantly

Answered by dreamrob
2

Program in JAVA

import java.util.*;

abstract class Distance

{

   abstract void travelTime(double distance , double speed);

}

class DistMKS extends Distance

{

   void travelTime(double distance , double speed)

   {

       double time = distance / speed;

       System.out.print("Time = " + time + "hr");

   }

   

}

public class MyClass {

   public static void main(String args[])

   {

       Scanner Sc = new Scanner(System.in);

       double dis;

       System.out.print("Enter distance between two points : ");

       dis = Sc.nextDouble();

       Distance obj = new DistMKS();  

       obj.travelTime(dis,100);

   }

}

Similar questions