0
0
C Sharp (C#)programming~10 mins

Constructor overloading in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a constructor that takes no parameters.

C Sharp (C#)
public class Car {
    public string Model;
    [1] {
        Model = "Unknown";
    }
}
Drag options to blanks, or click blank then click option'
ACar
BCar()
Cvoid Car()
Dpublic Car()
Attempts:
3 left
💡 Hint
Common Mistakes
Using a return type like void for the constructor.
Not matching the constructor name with the class name.
2fill in blank
medium

Complete the code to define a constructor that takes a string parameter.

C Sharp (C#)
public class Car {
    public string Model;
    [1] {
        Model = model;
    }
}
Drag options to blanks, or click blank then click option'
Apublic Car(string model)
BCar(string model)
Cvoid Car(string model)
DCar()
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the public keyword.
Adding a return type like void.
3fill in blank
hard

Fix the error in the constructor declaration.

C Sharp (C#)
public class Car {
    public string Model;
    [1] {
        Model = "Default";
    }
}
Drag options to blanks, or click blank then click option'
Apublic Car()
BCar()
Cvoid Car()
Dpublic void Car()
Attempts:
3 left
💡 Hint
Common Mistakes
Adding a return type like void.
Omitting the access modifier.
4fill in blank
hard

Fill both blanks to create two constructors: one default and one with a string parameter.

C Sharp (C#)
public class Car {
    public string Model;
    [1] {
        Model = "Unknown";
    }
    [2] {
        Model = model;
    }
}
Drag options to blanks, or click blank then click option'
Apublic Car()
BCar()
Cpublic Car(string model)
Dvoid Car(string model)
Attempts:
3 left
💡 Hint
Common Mistakes
Using void as a return type.
Omitting the access modifier.
5fill in blank
hard

Fill all three blanks to create a class with three overloaded constructors.

C Sharp (C#)
public class Car {
    public string Model;
    public int Year;

    [1] {
        Model = "Unknown";
        Year = 0;
    }

    [2] {
        Model = model;
        Year = 0;
    }

    [3] {
        Model = model;
        Year = year;
    }
}
Drag options to blanks, or click blank then click option'
Apublic Car()
Bpublic Car(string model)
Cpublic Car(string model, int year)
DCar(string model, int year)
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the public keyword.
Using the wrong constructor name.
Missing parameters or wrong parameter types.