Suppose you have created a program that creates instances of different types of
ID: 3704769 • Letter: S
Question
Suppose you have created a program that creates instances of different types of cars. Now you are creating a program that keeps track of different types of cars. Choose the abstract classes and concrete classes that you would like to use within the program in question. Provide at least one (1) example of each type of class and a description of each class’s function to support your choices. Using the scenario from Part I of this discussion, determine at least one (1) abstract method and at least one (1) non-abstract method that you would like to use in the program that you are creating. Include one (1) example of the application of each method to support your response.
Explanation / Answer
Hi Dear,
Please find my sample Car inheritance implementation.
You have not mention required programming language.
I have implemented in Java.
Car is an abstract class which has one concrete method start() and one abstract method defineMe(). PrivateCar and Taxi are two types of cars extending from Car class overriding the abstract method defineMe().
// abstract class
public abstract class Car
{
protected String color;
protected String fuelType;
// concrete method
public void start() {
System.out.println("Lock doors, Ignition! Ready to go.... ");
}
// abstract method
abstract void defineMe();
}
// child class
class PrivateCar extends Car {
PrivateCar(String c, String f)
{
fuelType=f;
color = c;
}
//overide abstract method of class Car
void defineMe()
{
System.out.println(" I am a private car running on "+fuelType+" and color "+color);
}
}
// child class
class Taxi extends Car {
int passengers;
Taxi(String c, String f, int p)
{
fuelType=f;
color = c;
passengers=p;
}
public void loadPassengers() {
System.out.println("Load Passengers, and move ");
start();
}
// Overiding abstract method of Car
void defineMe()
{
System.out.println(" I am a Taxi car running on "+fuelType+", color "+color+" and I have capacity of "+passengers+" passengers");
}
}
// Main Class or Driver class containg main method
public class AbstractDemoCar
{
public static void main(String a[]) {
PrivateCar c= new PrivateCar("White","Petrol");
Taxi t = new Taxi("Black","Diesel ", 10);
c.defineMe();
c.start();
t.defineMe();
t.loadPassengers();
}
}
Please DONT forgot to rate my answer. We are working hard for you Guys!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.