Solution Review: Implement the Derived Class
This review provides a detailed analysis to solve the 'Implement the Derived Class' challenge.
We'll cover the following...
Solution #
Press + to interact
// Base Classclass Vehicle {// Private Data Membersprivate String speed;private String model;public Vehicle() { // Default Constructorspeed = "100";model = "Tesla";}// Getter Functionpublic String getSpeed() {return speed;}// Getter Functionpublic String getModel() {return model;}}// Derived Classclass Car extends Vehicle {public String name; // Name of a Carpublic Car() { // Default Constructorname = "";}// This function sets the name of the carpublic void setDetails(String name) { // Setter Functionthis.name = name;}// This function calls the Base class functions and append the result with inputpublic String getDetails(String carName) {String details = carName + ", " + getModel() + ", " + getSpeed(); // calling Base Class Functionreturn details;}public static void main(String args[]) {Car car = new Car();System.out.println(car.getDetails("X"));}}
...