103k views
0 votes
Consider the following code snippet: public class Vehicle { private String type; private int numAxles; public Vehicle(String vehicleType, int VehicleAxles) { . . . } public Vehicle(String vehicleType) { . . . } } What is wrong with this code?

User Franssu
by
5.7k points

1 Answer

4 votes

Answer:

class Vehicle

{

private: //should be declared once

string type; //should be small as C++ is case sensitive

int numAxles;

public: //should be declared once

Vehicle ( string vehicleTypes, int VehicleAxles); \\s should be small as C++ is case sensitive and it is a parametarised constructor

Vehicle (string vehicleType, int b); //s should be small as C++ is case sensitive and now this is also a parametarised constructor

}; //a class ends with }: not with }

Step-by-step explanation:

There are two constructors in this piece of code. The first constructor was parametrised while the second only had one argument. The second constructor should have 2 arguments like the first construtor or it should be empty. I've passed another argument to the second constructor. Moreover, the class ends with }; not with } and as we know C++ is case sensitive language so, declare the reserved keywords with small letters.

User Adim
by
5.7k points