Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new instance of the class Car.
C Sharp (C#)
Car myCar = [1] Car(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'create' or 'make' instead of 'new' causes a syntax error.
Forgetting the 'new' keyword leads to a compile-time error.
✗ Incorrect
In C#, the keyword
new is used to create a new instance of a class.2fill in blank
mediumComplete the code to instantiate a Person object with the default constructor.
C Sharp (C#)
Person person = [1] Person(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'init' or 'create' instead of 'new' causes errors.
Omitting the keyword entirely results in a compile error.
✗ Incorrect
The
new keyword is required to instantiate an object in C#.3fill in blank
hardFix the error in the code to correctly instantiate a Book object.
C Sharp (C#)
Book myBook = [1]Book(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out the space after the keyword causes syntax errors.
Using incorrect keywords like 'create' or 'make' leads to errors.
✗ Incorrect
The
new keyword must be followed by the class name and parentheses to create an object.4fill in blank
hardFill both blanks to instantiate a Student object and assign it to a variable.
C Sharp (C#)
[1] [2] = new Student();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name twice causes syntax errors.
Using 'new' as a variable name is invalid.
✗ Incorrect
Use
var to let the compiler infer the type, and student as the variable name.5fill in blank
hardFill all three blanks to instantiate a Rectangle object with width and height parameters.
C Sharp (C#)
Rectangle [1] = new Rectangle([2], [3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name as a variable name causes confusion.
Swapping the width and height values changes the rectangle size.
✗ Incorrect
The variable name is
rect, and the constructor parameters are width=5 and height=10.