Ask Question
27 November, 07:47

In Java, write a constructor in such a way that a Vehicle object with color and type can be constructed directly via, say:

Vehicle ("Pink", "Car");

+3
Answers (1)
  1. 27 November, 08:42
    0
    In Java, a Constructor is similar to that of a method which will be called when creating a new object for the class. There is no return type for a Constructor. public Vehicle (String color, String type)

    {

    colourName = color;

    typeName = type;

    }

    In Java, you can use new operator to create an object of a class. Here, the object for the class Vehicle is created like Vehicle vehicle = new Vehicle ("Pink", "Car"); When creating the object of the class, the new operator calls the constructor. If there is no constructor defined explicitly, a default constructor is created by the compiler.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “In Java, write a constructor in such a way that a Vehicle object with color and type can be constructed directly via, say: Vehicle ("Pink", ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers