Which statement about a nested class in C++ is correct?

Options

  • A. A class can be declared inside another class
  • B. A nested class must always be declared outside every class
  • C. A nested class cannot have member functions
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. A class can be declared inside another class

Detailed Explanation

Answer: (A) A class can be declared inside another class

C++ allows one class to be declared inside another class. Such a class is called a nested class.

For example:

class Outer {

public:

  class Inner {

  public:

    void show() { }

  };

};

Here, Inner is nested inside Outer.