Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Multiple Choice Questions
Q491: If a class A declares a class B as its friend, what is the implication?
- A: B can access all private members of A
- B: A can access all private members of B
- C: B and A have mutual access to each other
- D: Neither class has special access to the other
View Answer
A
Q492: Can a class declare multiple classes as friends?
- A: No, only one friend class is allowed
- B: Yes, multiple friend classes can be declared
- C: Only if the classes are subclasses
- D: No, friend declarations are limited to functions
View Answer
B
Q493: What happens if you modify the private data member of a class using a friend function?
- A: The private data member remains unchanged
- B: The private data member is accessible to all functions
- C: The private data member is modified by the friend function
- D: The class’s private data is protected from changes
View Answer
C
Q494: Which of the following is true about friend functions?
- A: They can be members of the class they are friends with
- B: They can access private and protected members
- C: They must be declared in the public section
- D: They cannot access private data members
View Answer
B
Q495: What is the output if a friend function attempts to access a private member of a class?
- A: It results in a compilation error
- B: It has unrestricted access to private members
- C: It causes a runtime error
- D: It accesses public members only
View Answer
B
Q496: When declaring a friend function that needs to access private members of multiple classes, what must be done?
- A: Declare the friend function in one class only
- B: Declare the friend function in each class involved
- C: Declare the function as a member of one class
- D: Use an interface class for declaration
View Answer
B
Q497: What is the syntax to declare a class as a friend of another class in C++?
- A: friend class ClassName;
- B: class ClassName friend;
- C: friend ClassName;
- D: friend ClassName()
View Answer
A
Q498: If two classes are friends of each other, what type of access do they have?
- A: Mutual access to all private members
- B: Limited access to each other’s public members
- C: One-way access where each class can access the other’s private members
- D: No special access; they interact as normal classes
View Answer
A
Q499: What is a reference in C++?
- A: An alias or synonym for a data type
- B: A new variable
- C: A pointer to a data type
- D: An address of a variable
View Answer
A
Q500: How do you declare a reference in C++?
- A: int i &;
- B: int &i;
- C: &int i;
- D: ref int i;
View Answer
B