Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a class named Car.
C++
class [1] { public: void drive() {} };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using a different class name than requested.
β Incorrect
The class name should be Car as specified.
2fill in blank
mediumComplete the code to create an object named myCar of class Car.
C++
Car [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using the class name instead of the object name.
β Incorrect
The object name should be myCar as requested.
3fill in blank
hardFix the error in the code to access the drive method using the object myCar.
C++
myCar.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Capitalizing the method name incorrectly.
β Incorrect
The method name is drive exactly as declared in the class.
4fill in blank
hardFill both blanks to define a class Person with a private age and a public method to get age.
C++
class Person { private: int [1]; public: int [2]() { return age; } };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using wrong variable or method names.
β Incorrect
The private variable is named age and the public method to get it is getAge.
5fill in blank
hardFill all three blanks to implement inheritance where Student inherits from Person and adds a method to get grade.
C++
class Student : public [1] { public: int [2]() { return grade; } private: int [3]; };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using wrong base class or method names.
β Incorrect
Student inherits from Person. It has a method getGrade and a private variable grade.