Question:

One of the valid C++ class declaration is:

Show Hint

C++ is case-sensitive. Always write class in lowercase and end the class declaration with a semicolon.
Updated On: May 18, 2026
  • Class B {}
  • class B { int x; };
  • Public class B {}
  • Object B { int x; };
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Concept:
In C++, a class is declared using the lowercase keyword class. The class body is enclosed within braces and the declaration ends with a semicolon.

Step 1: General syntax of class declaration.
\[ \texttt{class ClassName \{ members; \};} \]

Step 2: Check option (A).

Class with capital C is not the C++ keyword. C++ is case-sensitive. \[ (A) \text{ is incorrect} \]

Step 3: Check option (B).

class B { int x; }; uses the correct keyword, correct braces, data member, and final semicolon. \[ (B) \text{ is correct} \]

Step 4: Check other options.

Public class is Java-style syntax, not valid C++. Object is not used to declare a class in C++. \[ \therefore \text{Correct Answer is (B)} \]
Was this answer helpful?
0
0