Complete the code to define a constructor that takes no parameters.
public class Car { public string Model; [1] { Model = "Unknown"; } }
The constructor must have the same name as the class and no return type. So public Car() is correct.
Complete the code to define a constructor that takes a string parameter.
public class Car { public string Model; [1] { Model = model; } }
public keyword.The constructor must be public and have the same name as the class with the parameter list. So public Car(string model) is correct.
Fix the error in the constructor declaration.
public class Car { public string Model; [1] { Model = "Default"; } }
Constructors must be public and have no return type. So public Car() is correct.
Fill both blanks to create two constructors: one default and one with a string parameter.
public class Car { public string Model; [1] { Model = "Unknown"; } [2] { Model = model; } }
The first constructor is the default one with no parameters: public Car(). The second constructor takes a string parameter: public Car(string model).
Fill all three blanks to create a class with three overloaded constructors.
public class Car { public string Model; public int Year; [1] { Model = "Unknown"; Year = 0; } [2] { Model = model; Year = 0; } [3] { Model = model; Year = year; } }
The class has three constructors: a default one with no parameters, one with a string parameter, and one with string and int parameters. All must be public and named after the class.