Respuesta :
Answer:
public abstract class Vehicle
{
private int id;
public int ID
{
get { return id; }
set { id = value; }
}
private string model;
public string Model
{
get { return model; }
set { model = value; }
}
public abstract string VehicleDetail(int id, string model);
}
public class Car : Vehicle
{
public Car() { }
public Car(int id, string model)
{
ID = id;
Model = model;
}
public override string VehicleDetail(int id, string model)
{
return $"{id} - {model}";
}
}
public class Bus : Vehicle
{
public Bus(int id, string model, string make)
{
ID = id;
Model = model;
Make = make;
}
public string Make { get; set; }
public override string VehicleDetail(int id, string model, string make)
{
return $"{id} - {model}" - {make};
}
}
Explanation:
Answer:
//Declare the abstract class
//by using the "abstract" keyword as follows
abstract class Vehicle {
//declare the attributes of the class
int id;
String model;
//declare the abstract method, vehicleDetail()
//which has two arguments: id and model
//and has no implementation
abstract void vehicleDetail(int id, String model);
} //End of abstract class declaration
========================================================
//Create the Car class to inherit from the Vehicle class
//by using the "extends" keyword as follows
public class Car extends Vehicle {
//Implement the abstract method in the Vehicle class
//writing statements to print out the id and model as follows;
void vehicleDetail(int id, String model) {
System.out.println("Id : " + id);
System.out.println("Model : " + model);
} //End of vehicleDetail method
} //End of class declaration
==========================================================
//Create the Bus class to inherit from the Vehicle class
//by using the "extends" keyword as follows
public class Bus extends Vehicle {
//Implement the abstract method in the Vehicle class
//by writing statements to print out the id and model as follows;
void vehicleDetail(int id, String model) {
System.out.println("Id : " + id);
System.out.println("Model : " + model);
} //End of vehicleDetail method
} //End of class declaration
================================================================
Explanation:
The above code has been written in Java and it contains comments explaining every line of the code. Please go through the comments.
The actual lines of code have been written in bold-face to differentiate them from comments.