Creating and printing a 'Vehicle' object in Java

Report a typo

Consider a base class named 'Vehicle' in Java, with a field 'name'. You need to create an object of 'Vehicle', assign the value 'Honda' to its 'name' field, and finally print the 'name' field using System.out.println(). Fill the blanks in the code provided to create an instance of 'Vehicle', assign the value, and print it.

Fill in the gaps with the relevant elements
public class  {
    String name;
    
    public static void (String[] args) {
        Vehicle car =  Vehicle();
        car.name = "Honda";
        System.out.println(car.name);
    }
}
mainVehiclenew
___

Create a free account to access the full topic