CS304 – Object Oriented Programming: Midterm Important Subjective (58 Solved Q&As)
Computer Science • Read every solved subjective question with its model answer directly on this page. Free, no login required.
All 664 Midterm Packs · CS304 Course Page · CS304 MCQ Pack (399 MCQs)
-
What is interface? Give two real life examples.
Topic: OOP Fundamentals — Classes, Objects & Encapsulation
Interface is a set of functions of an object that it wants to expose to other objects. Interface of a Car is the set of these functions: Accelerate, Change Gear, Apply Brakes, Turn Lights On/Off. Interface of a Phone is the set of these functions: Input Number, Place Call, Disconnect Call, Add number to address book, Remove number, Update number.
-
What is an abstract class?
Topic: OOP Fundamentals — Classes, Objects & Encapsulation
Taking part of the objects and their functions that is related to the problem and ignoring all other irrelevant characteristics is called abstraction. (The source answer defines abstraction, on which the concept of an abstract class is based.)
-
What are Accessor Functions? Explain with an example. (Marks: 5)
Topic: OOP Fundamentals — Classes, Objects & Encapsulation
Accessor functions are used to access private data of the object. We provide accessor functions to get and set private data members of the class. class Student { ... int rollNo; public: void setRollNo(int aRollNo) { rollNo = aRollNo; } }; Avoiding error — the setter can validate the value before assigning it: void Student::setRollNo(int aRollNo) { if (aRollNo < 0) { rollNo = 0; } else { rollNo = aRollNo; } }
-
Explain two benefits of setter functions. (Marks: 2)
Topic: OOP Fundamentals — Classes, Objects & Encapsulation
Setter (and getter) functions are provided by the class to access its members. Their benefits are: 1. They help to define the variable in an interface, and can be used to make a variable read-only, and to notify other methods/classes when the value is changed. 2. They minimize the chances of moving the object into an inconsistent state, because we can write checks in our setter functions — for example, we can check whether the user has entered a correct age value and has not entered a negative value for age.
-
Explain the scope of 'private' member of a class with one example. (Marks: 2)
Topic: OOP Fundamentals — Classes, Objects & Encapsulation
The scope of a private data member of a class is that access is allowed only within the class. Only member functions of the class can access and modify the value of the data member. A derived class or a class instance/object cannot access it directly. The data member is created for each separate object in memory and is eliminated when the object is destroyed; an object is destroyed by calling its destructor. class Arithmetic { private: int a, b; public: void Add() { // a + b; direct access by member function — correct access } }; int main() { Arithmetic c1; c1.a = 4; // illegal access to private data member — compiler error }
-
If, within a class, da is a member variable, will the statement this.da = 25; assign 25 to da? (Marks: 2)
Topic: OOP Fundamentals — Classes, Objects & Encapsulation
No — the statement is false/incorrect. 'this' is a pointer, so when using a pointer to an object we use the -> operator to access the object's member functions and data members. The correct statement is: this->da = 25;
-
Can a constant object access the non-constant member function of a class?
Topic: OOP Fundamentals — Classes, Objects & Encapsulation
No. Const objects can access only const member functions, so chances of change of state of const objects once they are created are eliminated.
-
Write three important properties of constructors. Also tell the reason why we cannot overload the following four operators in C++: . , .* , :: , ?: — and, considering the Complex number class, can we subtract two complex numbers by overloading the plus '+' operator? Justify your answer.
Topic: Constructors, Object Arrays & Initialization Order
Properties of constructors: 1. Constructor is a special function having the same name as the class name. 2. Constructor does not have a return type. 3. Constructors are commonly public members. The operators . , .* , :: and ?: cannot be overloaded because they are strictly compile-time operators: they are defined for all types, operate on names rather than values, and have results which can be used in constant expressions (evaluated at compile time). Subtracting through operator+: No. An overloaded operator must keep its natural, intuitive meaning; writing subtraction code inside operator+ would be misleading and against the purpose of operator overloading. Subtraction of two complex numbers must be implemented by overloading the '-' operator. (Note: the answer to the last part — subtracting through operator+ — is written from course knowledge; the source answer covers only the constructor properties and the non-overloadable operators.)
-
Can we create an array of objects for a class having user defined constructor? Justify your answer. (Marks: 2)
Topic: Constructors, Object Arrays & Initialization Order
No — not with a user defined (parameterized) constructor alone. When an array of objects is created, every element has to be constructed without arguments, so there must always be a default constructor if we want to create an array of objects. If the class provides only a user defined constructor, an array of objects cannot be created unless a default constructor is also defined.
-
Can we create an array of objects for a class having default constructor? Justify your answer. (Marks: 2)
Topic: Constructors, Object Arrays & Initialization Order
Yes. When an array of objects is created, the constructor is called for each element of the array. Since no arguments can be supplied while creating an array, the default constructor (the constructor with no parameters) is invoked for every element. Therefore, if a class has a default constructor, an array of its objects can be created, and each element is initialized by that default constructor.
-
Consider the class given below. Explain the order in which variables e, f and g will be initialized after creating an object of this class.
Topic: Constructors, Object Arrays & Initialization Order
class XYZ { int e; int f; int g; public: XYZ(); }; XYZ::XYZ() : g(30), e(10), f(20) { ... } Member variables are initialized in the order in which they are declared in the class, not in the order in which they appear in the member initializer list. The declaration order here is e, f, g, so they are initialized in the order e first, then f, then g — giving the values e = 10, f = 20 and g = 30. (Note: the source file prints the values as 'f = 30 and g = 20', which appears to be a printing error in the source — the initializer list assigns f(20) and g(30).)
-
Consider the class given below. What will be the values in variables x, y and z after creating an object of this class? (Marks: 3)
Topic: Constructors, Object Arrays & Initialization Order
class ABC { int x; int y; int z; public: ABC(); }; ABC::ABC() : x(10), z(x), y(x) { ... } Variables are initialized in the order of their declaration in the class (x, y, z), regardless of the order in the initializer list. So x is initialized first with 10; then y is initialized with the value of x, i.e. 10; then z is initialized with the value of x, i.e. 10. x = 10, y = 10 and z = 10.
-
What are static data members? (Marks: 2)
Topic: Static Members
A variable that is part of a class, yet is not part of any object of that class, is called a static data member.
-
Explain the difference between the static variable of a class and the non-static variable, with the help of an example.
Topic: Static Members
The difference between static and non-static members is only that a non-static member is tied to an instance of a class, whereas a static member is tied to the class and not to a particular instance. That is, a static member is shared by all instances of a class, although a non-static member exists separately for each instance of the class. Example: in a Student class, rollNo is a non-static member — every student object has its own rollNo. A static member such as a counter of students is shared by all objects, so increasing it through any one object is visible to all objects of the class.
-
Friend functions increase 'Programming bugs'. What is your opinion? (Marks: 2)
Topic: Friend Functions
Yes, friend functions can increase programming bugs. A friend function can access the private data of a class, which minimizes encapsulation. This can result in data vulnerability, programming bugs and tough debugging.
-
Friend functions minimize 'Encapsulation'. What is your opinion?
Topic: Friend Functions
Yes, friend functions minimize encapsulation, as we can access the private data of any class using friend functions. This can result in: • Data vulnerability • Programming bugs • Tough debugging
-
Friend functions increase 'Data vulnerability'. What is your opinion? (Marks: 2)
Topic: Friend Functions
Yes. Friend functions minimize encapsulation, as we can access the private data of any class using friend functions. This can result in: • Data vulnerability • Programming bugs • Tough debugging
-
What is simple association? Explain it with the help of an example.
Topic: Object Relationships — Association, Aggregation & Composition
The two interacting objects have no intrinsic relationship with the other object. It is the weakest link between objects. It is a reference by which one object can interact with some other object. Examples: • Customer gets cash from cashier. • Employee works for a company.
-
What is the difference between simple association and composition?
Topic: Object Relationships — Association, Aggregation & Composition
In Association, the interacting objects have no intrinsic relationship with the other object. It is the weakest link between objects. While in Composition, an object may be composed of other smaller objects; the relationship is between the 'part' objects and the 'whole' object, and the part objects are dependent on the whole object for their existence.
-
What is aggregation? Give an example.
Topic: Object Relationships — Association, Aggregation & Composition
An object may contain a collection (aggregate) of other objects; the relationship between the container and the contained object is called aggregation. For example, a room and its components like table, chair and bed etc. are an example of aggregation.
-
What is composition? Explain it with the help of an example. (Marks: 5)
Topic: Object Relationships — Association, Aggregation & Composition
An object may be composed of other smaller objects; the relationship between the 'part' objects and the 'whole' object is known as Composition. Composition is represented by a line with a filled-diamond head towards the composer object. For example, a man and his body parts have the relation of 'part' objects and the 'whole' object — this is known as the composition of man.
-
What are binary operators? Give an example of binary operator overloading using any class. (Marks: 3)
Topic: Operator Overloading — Concepts & Arithmetic Operators
Binary operators act on two quantities. Examples of binary operators are +, -, * and /. Overloading of the + operator for a Complex class: class Complex { private: double real, img; public: ... Complex operator +(const Complex & rhs); }; Complex Complex::operator +(const Complex & rhs) { Complex t; t.real = real + rhs.real; t.img = img + rhs.img; return t; } The binary operator is always called with reference to the left hand argument.
-
Give C++ code to overload the unary '--' operator for the Complex class. (Marks: 3)
Topic: Operator Overloading — Concepts & Arithmetic Operators
class Complex { ... Complex operator --(int); // postfix, as member function // friend Complex operator --(const Complex &, int); }; Complex Complex::operator --(int) { Complex t = *this; real -= 1; return t; } // As a friend (non-member) function: Complex operator --(const Complex & h, int) { Complex t = h; t.real -= 1; return t; }
-
Write C++ code for overloading the '^' operator in the Complex numbers class. If we have two objects of the Complex number class, Complex obj1, obj2; and we write the statement Complex obj3 = obj1 ^ obj2; then obj3.real = (obj1.real)^(obj2.real) and obj3.img = (obj1.img)^(obj2.img). (Hint: You can use the C++ built-in function pow(x, y) that returns the result of x raised to the power y.) (Marks: 5)
Topic: Operator Overloading — Concepts & Arithmetic Operators
class Complex { double real, img; public: Complex operator ^(const Complex & c) { Complex t; t.real = pow(real, c.real); t.img = pow(img, c.img); return t; } }; When the statement Complex obj3 = obj1 ^ obj2; is executed, the overloaded ^ operator is called on obj1 with obj2 as argument, so obj3.real gets (obj1.real) raised to the power (obj2.real) and obj3.img gets (obj1.img) raised to the power (obj2.img), computed with the built-in pow(x, y) function.
-
Write C++ code for overloading the '-' operator in the Complex numbers class which can work in the given situations: Complex obj1; Complex obj3 = 47.4 - obj2; Complex obj4 = obj2 - 47.4; (Marks: 5)
Topic: Operator Overloading — Concepts & Arithmetic Operators
We make one version a friend function so that it can be written as a non-member function: when the left operand is a double value (47.4 - obj2), the operator is not called with respect to a Complex object; instead both arguments (the double value and the Complex object) are passed to the friend function, and the compiler invokes the function according to the arguments passed. The case obj2 - 47.4 is handled by the member function. class Complex { private: double real, img; public: friend Complex operator -(double c1, Complex obj); Complex operator -(double c1) { Complex temp; temp.real = real - c1; temp.img = img - c1; return temp; } }; // Friend function definition — handles 47.4 - obj2 Complex operator -(double c1, Complex obj) { Complex temp; temp.real = c1 - obj.real; temp.img = c1 - obj.img; return temp; }
-
Assuming that class X does not use any overloaded operators and has a member function to subtract two objects of X, placing the result in the third object using which it has been called, write a statement that we will use to subtract two objects of class X, placing the result in the third object. You can take any names for the three objects of X. (Marks: 3)
Topic: Operator Overloading — Concepts & Arithmetic Operators
obj3.subtract(obj1, obj2); Here the member function subtract is called using the third object obj3, and the two objects to be subtracted (obj1 and obj2) are passed to it as arguments. The function subtracts them and places (stores) the result in the calling object obj3 itself.
-
Give C++ code to overload the assignment operator for the String class. (Marks: 3)
Topic: Assignment Operator, Copying & Special Operators
class String { int size; char * bufferPtr; public: String(); // default constructor String(char *); // overloaded constructor String(const String &); // copy constructor ... }; String::String() { bufferPtr = NULL; size = 0; } String::String(char * ptr) { if (ptr != NULL) { size = strlen(ptr); bufferPtr = new char[size + 1]; strcpy(bufferPtr, ptr); } else { bufferPtr = NULL; size = 0; } } String::String(const String & rhs) { size = rhs.size; if (rhs.size != 0) { bufferPtr = new char[size + 1]; strcpy(bufferPtr, rhs.bufferPtr); } else { bufferPtr = NULL; } } int main() { String str1("Hello"); String str2("World"); str1 = str2; return 0; }
-
Give at least two problems that we should check when we are overloading the assignment operator ("=") in the String class.
Topic: Assignment Operator, Copying & Special Operators
1. Self-assignment (self-referencing): an object may be assigned to itself, e.g. str = str; The overloaded assignment operator must check for this case, otherwise it would first delete its own buffer and then try to copy data from the already-freed memory, corrupting the object. 2. Chained (cascaded) assignment: assignments in a single line such as stringObject1 = stringObject2 = stringObject3 = stringObject4 must work. For this, the assignment operator must return a reference to the assigned object (String &) so that the result of one assignment can be used as the operand of the next. (Related: the old memory of the destination object must also be released properly, otherwise memory leakage and dangling pointers occur.)
-
How do we resolve the following problems in overloading of the assignment operator in the String class? Explain with the help of C++ code. (i) Self referencing. (ii) Assigning a string value to more than one string in a single line, like stringObject1 = stringObject2 = stringObject3 = stringObject4.
Topic: Assignment Operator, Copying & Special Operators
Both problems are resolved by defining the assignment operator to return a reference to the object itself (String &) and by guarding against self-assignment before releasing the old buffer: class String { ... public: ... String & operator = (const String &); }; String & String::operator = (const String & rhs) { if (this != &rhs) { // protects against self-assignment size = rhs.size; delete [] bufferPtr; if (rhs.size != 0) { bufferPtr = new char[rhs.size + 1]; strcpy(bufferPtr, rhs.bufferPtr); } else { bufferPtr = NULL; } } return *this; // enables chained assignment } Returning *this by reference makes chained assignment work, because the result of stringObject2 = stringObject3 is stringObject2 itself, which is then assigned to stringObject1, and so on.
-
Explain what type of copy the default assignment operator "=" does when applied to objects (shallow copy or deep copy). (Marks: 3)
Topic: Assignment Operator, Copying & Special Operators
The default assignment operator performs a shallow copy. If our class has any data member using dynamic memory, then we have to write our own code for the default constructor, copy constructor and similarly the assignment operator, because the compiler-generated versions of these functions perform shallow copy, which creates dangling pointer and memory leakage issues in case of dynamic memory allocation.
-
Write C++ code to overload the subscript [] operator for the String class. (Marks: 5)
Topic: Assignment Operator, Copying & Special Operators
The subscript operator must be overloaded as a member function of the class with one parameter of integer type: class String { ... public: char & operator[](int); ... }; char & String::operator[](int pos) { assert(pos > 0 && pos <= size); return stringPtr[pos - 1]; } int main() { String s1("Ping"); cout << s1.GetString() << endl; s1[2] = 'o'; cout << s1.GetString(); return 0; }
-
Write C++ code for the operator() (function operator). (Marks: 5)
Topic: Assignment Operator, Copying & Special Operators
class String { ... public: char & operator()(int); ... }; char & String::operator()(int pos) { assert(pos > 0 && pos <= size); return bufferPtr[pos - 1]; } int main() { String s1("Ping"); char g = s1(2); // g = 'i' s1(2) = 'o'; cout << g << "\n"; cout << s1.GetString(); return 0; }
-
How can we overload the Stream Extraction and Insertion Operators in C++? Give example code for the Complex Number Class. (Marks: 5)
Topic: Assignment Operator, Copying & Special Operators
The stream insertion (<<) and extraction (>>) operators are overloaded as friend functions of the class, because their left operand is a stream object, not an object of our class. class Complex { ... friend ostream & operator << (ostream & os, const Complex & c); friend istream & operator >> (istream & in, Complex & c); }; // Stream insertion operator — we want the output as: (real, img) ostream & operator << (ostream & os, const Complex & c) { os << '(' << c.real << ',' << c.img << ')'; return os; } // Stream extraction operator istream & operator >> (istream & in, Complex & c) { in >> c.real >> c.img; return in; } (Note: the source gives the insertion operator in full but the file ends after the declaration of the extraction operator; the extraction operator's definition above is completed from course knowledge — not in sources.)
-
Detect and correct the compile time error(s) in the following code. (Marks: 5)
Topic: Finding & Correcting Errors in Code
Code given in the paper: class Exam { char *ExamName; int No_of_paper; public: Exam() { ExamName = "Final Term"; No_of_paper = 5; } void setname(char* name) const { ExamName = name; } void setpaper(int paper) const { No_of_paper = paper; } char* getname() { return ExamName; } int getpaper() { return No_of_paper; } }; int main() { const Exam exam1; cout << " Exam = " << exam1.getname() << endl; cout << " Number of paper = " << exam1.getpaper(); getch(); return 0; } Errors: (1) setname and setpaper are declared const, but a const member function cannot modify the data members of the class — assigning ExamName and No_of_paper inside them is a compile time error. (2) exam1 is declared as a const object in main, and a const object can call only const member functions, whereas getname and getpaper are non-const member functions — calling them on exam1 is also a compile time error. Corrected code: class Exam { char *ExamName; int No_of_paper; public: Exam() { ExamName = "Final Term"; No_of_paper = 5; } void setname(char* name) { ExamName = name; } void setpaper(int paper) { No_of_paper = paper; } char* getname() { return ExamName; } int getpaper() { return No_of_paper; } }; int main() { Exam exam1; cout << " Exam = " << exam1.getname() << endl; cout << " Number of paper = " << exam1.getpaper(); getch(); return 0; }
-
What is Abstraction?
Topic: Important Definitions — OOP Concepts
The importance of abstraction is derived from its ability to hide irrelevant details and from the use of names to reference objects. Abstraction is essential in the construction of programs. It places the emphasis on what an object is or does rather than how it is represented or how it works. Thus, it is the primary means of managing complexity in large programs.
-
What is a Class Diagram?
Topic: Important Definitions — OOP Concepts
A class diagrams are widely used to describe the types of objects in a system and their relationships. Class diagrams model class structure and contents using design elements such as classes, packages and objects.
-
What is Method Overriding?
Topic: Important Definitions — OOP Concepts
Method overriding is a language feature that allows a subclass to override a specific implementation of a method that is already provided by one of its super-classes. A subclass can give its own definition of methods but need to have the same signature as the method in its super-class. This means that when overriding a method the subclass's method has to have the same name and parameter list as the super-class's overridden method.
-
What is Operator Overloading?
Topic: Important Definitions — OOP Concepts
The operator overloading is a specific case of polymorphisms in which some or all of operators like +, - or == are treated as polymorphic (multi) functions and as such have different behaviors depending on the types of its arguments.
-
What is Method Overloading?
Topic: Important Definitions — OOP Concepts
The method overloading is the ability to define several methods (in same class) all with the same name but different on the basis of i) number of parameters ii) types of parameters.
-
What is Polymorphism?
Topic: Important Definitions — OOP Concepts
Polymorphism is a generic term that means 'many shapes'. More precisely Polymorphism means the ability to request that the same operations be performed by a wide range of different types of things.
-
What is Inheritance?
Topic: Important Definitions — OOP Concepts
Ability of a new class to be created, from an existing class by extending it, is called inheritance.
-
What is a base class?
Topic: Important Definitions — OOP Concepts
When inheritance is used to create a new class from another, the new class is called the subclass or derived class, and the class from which it was derived is called the base class.
-
What is a concrete class?
Topic: Important Definitions — OOP Concepts
A concrete class is one that can be used to directly create, or instantiate objects, unlike an abstract base class which can only be used as a base class for other classes which eventually lead to concrete classes
-
What is a constructor?
Topic: Important Definitions — OOP Concepts
Objects are complete, miniature programs and, like any good programs, have well defined initialization and termination phases. They have special routines (i.e. member functions ) to look after this. The initialization routine is called the constructor, and C++ ensures that every object is properly initialized by calling its constructor. The designer of the object can have more than one constructor, a situation called overloading and then the compiler will select between them depending on exactly what arguments are passed to the constructor function. However there must always be a default constructor, to be used when no information is supplied.
-
What is a destructor?
Topic: Important Definitions — OOP Concepts
The termination routine is called the destructor, and C++ will provide a default if none is supplied. If, during the lifetime of the object, it uses heap memory then the designer of the object must provide a destructor function to release such memory to avoid a memory leak.
-
What is meant by protected?
Topic: Important Definitions — OOP Concepts
The protected keyword in the class statement means that the following members of the class are not available to users of the objects of the class, but can be used by any subclass that inherits from it, and consequently forms part of its implementation.
-
What is OOP?
Topic: Important Definitions — OOP Concepts
The object oriented programming is commonly known as OOP. Most of the languages are developed using OOP concept. Object-oriented programming (OOP) is a programming concept that uses "objects" to develop a system. An object hides the implementation details and exposes only the functionalities and parameters it requires to its client. Here also an object shares the same concept as that of a bike. While driving a motor bike, we are unaware of its implementation details such as how it is developed, internal working of gears etc.? We know only the functions or actions it can perform.
-
What are the various elements of OOP?
Topic: Important Definitions — OOP Concepts
Various elements of OOP are: Object, Class, Methods, Encapsulation, Information Hiding, Inheritance and Polymorphism.
-
What is an Object?
Topic: Important Definitions — OOP Concepts
An object has state, behavior and identity; the structure and behavior of similar objects are defined in their common class. The terms instance and object are interchangeable. An object is a tangible entity that exhibits some well-defined behavior.
-
What is Encapsulation?
Topic: Important Definitions — OOP Concepts
Encapsulation is the process of hiding all of the details of an object that do not contribute to its essential characteristics. It is the principle that each component of a program should encapsulate (hide) its implementation details, exposing only a well-defined interface to the rest of the system — this is also called information hiding.
-
What is the proper syntax to free the memory allocated to an array "a" of five objects?
Topic: Code & Short Questions from Past Papers
delete [] a; — The delete[] operator deallocates the memory of the whole array and calls the destructor for each of the five objects.
-
Write a class Coordinate that performs the mathematical operations (Addition and Multiplication) on its coordinates with the help of operator overloading. The class has two private data members: xCord and yCord.
Topic: Code & Short Questions from Past Papers
class Coordinate { private: int xCord; int yCord; public: Coordinate(int x = 0, int y = 0) { xCord = x; yCord = y; } Coordinate operator + (const Coordinate &c) { return Coordinate(xCord + c.xCord, yCord + c.yCord); } Coordinate operator * (const Coordinate &c) { return Coordinate(xCord * c.xCord, yCord * c.yCord); } };
-
Write any two advantages of declaring a member function as const.
Topic: Code & Short Questions from Past Papers
1) A const member function can be called on constant objects, so constant objects can still use the read-only (getter) functions of the class. 2) It guarantees that the function will not modify the data members of the object, which makes the program safer and lets the compiler catch accidental changes to the state of the object.
-
Write the code for a deep copy constructor for the given class: class MidTerm { private: char* papername; int Totalmarks; };
Topic: Code & Short Questions from Past Papers
MidTerm(const MidTerm &obj) { Totalmarks = obj.Totalmarks; papername = new char[strlen(obj.papername) + 1]; strcpy(papername, obj.papername); } In a deep copy, separate memory is allocated for the pointer data member and the contents are copied, so both objects own independent copies of the data.
-
Write the exact type of the this pointer in a member function of a class XYZ.
Topic: Code & Short Questions from Past Papers
In a non-const member function, the this pointer is of type XYZ* (it is a constant pointer that holds the address of the object itself). In a const member function, its type is const XYZ*, so the object cannot be modified through it.
-
Write three distinct situations in which the copy constructor of a class is called.
Topic: Code & Short Questions from Past Papers
1) When an object is initialized with another object of the same class, e.g. Student s2 = s1; 2) When an object is passed by value as an argument to a function. 3) When an object is returned by value from a function.
-
Consider the code: class Complex { private: double x, y; static int z; public: Complex(double = 0.0); friend ostream& operator<<(ostream&, const Complex&); static int doSomething() { z = 2 * y; return z; } }; What is wrong in the definition of member function doSomething()?
Topic: Code & Short Questions from Past Papers
doSomething() is a static member function. Static member functions have no this pointer and can access only the static data members of the class; here it tries to use y, which is a non-static data member, so the code is wrong and will not compile.
-
What will be the effect of writing the friend function operator<< in the private part of the above class?
Topic: Code & Short Questions from Past Papers
There will be no effect. Access specifiers (public, private, protected) do not apply to friend declarations: a friend function or friend class has full access to the private and protected members of the class no matter in which section of the class it is declared.