Skip to main content

Classes and Objects

1).What is a class in C++?

1) A user-defined data type
2) A built-in data type
3) A predefined function
4) None of the above

2).How do you create an object of a class in C++?

1) className obj;
2) obj className;
3) object className;
4) None of the above

3).Which access specifier allows members to be accessed outside the class?

1) private
2) protected
3) public
4) None of the above

4).Which of the following defines a constructor in a class?

class Example {
public:
  Example() { }
};
1) Correct syntax
2) Error: Missing return type
3) Error: Missing parameters
4) None of the above

5).How do you define a member function outside a class?

1) Using :: operator
2) Using . operator
3) Using -> operator
4) None of the above

6).Which operator is used to access members of a class through a pointer?

1) .
2) ->
3) ::
4) None of the above

7).What is the default access specifier for members in a class?

1) private
2) protected
3) public
4) None of the above

8).What happens if a constructor is not defined in a class?

1) Compiler provides a default constructor
2) Error is thrown
3) Class cannot be used
4) None of the above

9).What is a friend function in a class?

1) A function declared outside but has access to private members
2) A member function that is private
3) A function that belongs to a derived class
4) None of the above

10).Which member function is called automatically when an object is destroyed?

1) Destructor
2) Constructor
3) Friend function
4) None of the above