Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a class named Car.
C Sharp (C#)
public [1] Car { // class body }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'method' or 'variable' instead of 'class' to declare a class.
Confusing 'interface' with 'class' keyword.
✗ Incorrect
The keyword class is used to declare a class in C#.
2fill in blank
mediumComplete the code to create an object of the Car class.
C Sharp (C#)
Car myCar = new [1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different class name than the one declared.
Using 'Object' or 'Class' instead of the class name.
✗ Incorrect
To create an object, use the class name with the new keyword.
3fill in blank
hardFix the error in the code to access the Car's speed property.
C Sharp (C#)
int speed = myCar.[1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding parentheses when accessing a property.
Using incorrect capitalization.
✗ Incorrect
Properties are accessed without parentheses and with correct capitalization.
4fill in blank
hardFill both blanks to define a method named Drive inside the Car class.
C Sharp (C#)
public [1] [2]() { Console.WriteLine("Driving"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name as the method name.
Using a return type other than void when no value is returned.
✗ Incorrect
The method return type is void and the method name is Drive.
5fill in blank
hardFill all three blanks to create a Car object, set its speed, and print it.
C Sharp (C#)
Car [1] = new Car(); [1].[2] = 60; Console.WriteLine([1].[2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different object names in different lines.
Using incorrect property names or capitalization.
✗ Incorrect
Use the same object name myCar and the correct property name Speed to set and print the speed.