Question 78

Computer Awareness Object Oriented Programming Easy

Which of the following is a valid class declaration?

(A) class A {int x};
(B) class B { }
(C) public class A}
(D) object A {int x;);
View Dynamic Solution & Explanation
Correct Solution: Option B

Step-by-step Solution:

- (a) class A {int x} : Invalid syntax as class members must be defined properly. \[\] - (b) class B { }: Valid syntax. This declares an empty class in C++. \[\] - (c) public class A}: Invalid syntax. The `public` keyword does not belong outside a scope. \[\] - (d) object A {int x;); : Invalid syntax. `object` is not a valid keyword in C++. \[\] \[\] Correct Answer The valid class declaration is: class B \ \[\] Correct Answer: (b)