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
3
Answer:
Hope it helps, mark me brainliest
Follow me on Brainly, so whenever you ask questions, I can answer instantly
Answered by
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
Accountancy,
2 months ago
Chemistry,
2 months ago
Math,
4 months ago
History,
9 months ago
English,
9 months ago