0
0
C++programming~10 mins

OOP principles overview in 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 declare a class named Car.

C++
class [1] {
public:
    void drive() {}
};
Drag options to blanks, or click blank then click option'
ACar
BVehicle
CDrive
DEngine
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using a different class name than requested.
2fill in blank
medium

Complete the code to create an object named myCar of class Car.

C++
Car [1];
Drag options to blanks, or click blank then click option'
AmyCar
Bdrive
CCar
Dvehicle
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using the class name instead of the object name.
3fill in blank
hard

Fix 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'
Adrives
BDrive
Cdrive
DdriveCar
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Capitalizing the method name incorrectly.
4fill in blank
hard

Fill 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'
Aage
BgetAge
CsetAge
DageValue
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using wrong variable or method names.
5fill in blank
hard

Fill 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'
APerson
BgetGrade
Cgrade
DStudent
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using wrong base class or method names.