Which is correct syntax of inheritance?
2023
Which is correct syntax of inheritance?
- A.
class base_classname : access derived_classname
{
/* define class body */
};
- B.
class derived_classname : access base_classname
{
/* define class body */
};
- C.
class derived_classname : base_classname
{
/* define class body */
};
- D.
More than one of the above
- E.
None of the above
Attempted by 317 students.
Show answer & explanation
Correct answer: B
The correct syntax for C++ inheritance is: class derived_classname : access_specifier base_classname { ... };. Option B matches this. Option A reverses the order. Option C is missing the access specifier. Option D and E are incorrect as only B is valid.