Classes And Objects In C Plus Plus — Part 2 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Classes And Objects In C Plus Plus — Part 2 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress | 0/40 answered
✓ 0 correct
✗ 0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main () { string str ("microsoft"); string::reverse_iterator r; for (r = str.rbegin() ; r < str.rend(); r++ ) cout << *r; return 0; }
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How to declare the complex number?
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Given the following C++ code. How would you define the < operator for Box class so that when boxes b1 and b2 are compared in if block the program gives correct result? #include <iostream> #include <string> using namespace std; class Box { int capacity; public: Box(){} Box(double capacity){ this->capacity = capacity; } }; int main(int argc, char const *argv[]) { Box b1(10); Box b2 = Box(14); if(b1 < b2){ cout<<"Box 2 has large capacity."; } else{ cout<<"Box 1 has large capacity."; } return 0; }
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class sample { public: sample(int i) : m_i(i) { } public: int operator()(int i = 0) const { return m_i + i; } operator int () const { return m_i; } private: int m_i; friend int g(const sample&); }; int f(char c) { return c; } int main() { sample f(2); cout << f(2); return 0; }
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main () { string str ("example."); str.front() = 'E'; cout << str << endl; return 0; }
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which container in c++ will take large objects?
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many types of models are available to create the user-defined data type?
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which concepts does the Pre Increment use?
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which is the correct example of a binary operator?
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main () { string str = "HelloWorld!"; cout<<str.capacity(); cout<<str.size(); return 0; }
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <string> #include <cstring> using namespace std; int main(int argc, char const *argv[]) { string s("a"); cout<<s; return 0; }
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following operator can be used to overload when that function is declared as friend function?
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main(int argc, char const *argv[]) { char s1[6] = "Hello"; char s2[6] = "World"; char s3[12] = s1 + " " + s2; cout<<s3; return 0; }
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The data members and functions of a class in C++ are by default . . . . . . . .
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many arguments will the subscript operator will take for overloading?
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { static int a; public: A() { cout<<"Object of A is created\n"; } void show() { a++; cout<<"a: "<<a<<endl; } }; class B { public: }; int main(int argc, char const *argv[]) { A a1, a2; A a3 = a1 + a2; return 0; }
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
#include <iostream> using namespace std; class three_d { int x, y, z; public: three_d() { x = y = z = 0; } three_d(int i, int j, int k) { x = i; y = j; z = k; } three_d operator()(three_d obj); three_d operator()(int a, int b, int c); friend ostream &operator<<(ostream &strm, three_d op); }; three_d three_d::operator()(three_d obj) { three_d temp; temp.x = (x + obj.x) / 2; temp.y = (y + obj.y) / 2; temp.z = (z + obj.z) / 2; return temp; } three_d three_d::operator()(int a, int b, int c) { three_d temp; temp.x = x + a; temp.y = y + b; temp.z = z + c; return temp; } ostream &operator<<(ostream &strm, three_d op) { strm << op.x << ", " << op.y << ", " << op.z << endl; return strm; } int main() { three_d objA(1, 2, 3), objB(10, 10, 10), objC; objC = objA(objB(100, 200, 300)); cout << objC; return 0; }
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class sample { private: int* i; int j; public: sample (int j); ~sample (); int& operator [] (int n); }; int& sample::operator [] (int n) { return i[n]; } sample::sample (int j) { i = new int [j]; j = j; } sample::~sample () { delete [] i; } int main () { sample m (5); m [0] = 25; m [1] = 20; m [2] = 15; m [3] = 10; m [4] = 5; for (int n = 0; n < 5; ++ n) cout << m [n]; return 0; }
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How many specifiers are present in access specifiers in class?
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which special character is used to mark the end of class?
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <stdio.h> #include<iostream> using namespace std; int main() { int x = 5, y = 5; cout << ++x << --y << endl; return 0; }
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How to access the object in the class?
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class base { int val1, val2; public: int get() { val1 = 100; val2 = 300; } friend float mean(base ob); }; float mean(base ob) { return float(ob.val1 + ob.val2) / 2; } int main() { base obj; obj.get(); cout << mean(obj); return 0; }
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class complex { int i; int j; public: complex(int a, int b) { i = a; j = b; } complex operator+(complex c) { complex temp; temp.i = this->i + c.i; temp.j = this->j + c.j; return temp; } void show(){ cout<<"Complex Number: "<<i<<" + i"<<j<<endl; } }; int main(int argc, char const *argv[]) { complex c1(1,2); complex c2(3,4); complex c3 = c1 + c2; c3.show(); return 0; }
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In case of non-static member functions how many maximum object arguments a unary operator overloaded function can take?
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class sample1 { float i, j; }; class sample2 { int x, y; public: sample2 (int a, int b) { x = a; y = b; } int result() { return x + y; } }; int main () { sample1 d; sample2 * padd; padd = (sample2*) &d; cout<< padd->result(); return 0; }
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <string> #include <cstring> using namespace std; int main(int argc, char const *argv[]) { const char *a = "Hello\0World"; cout<<a; return 0; }
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; class A { static int a; public: void change(int i){ a = i; } void value_of_a(){ cout<<a; } }; int A::a = 5; int main(int argc, char const *argv[]) { A a1 = A(); A a2 = A(); A a3 = A(); a1.change(10); a1.value_of_a(); a2.value_of_a(); a3.value_of_a(); return 0; }
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Inline functions are avoided when . . . . . . . .
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class rect { int x, y; public: void val (int, int); int area () { return (x * y); } }; void rect::val (int a, int b) { x = a; y = b; } int main () { rect rect; rect.val (3, 4); cout << "rect area: " << rect.area(); return 0; }
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is a friend function in C++?
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; class Box { double length; double breadth; double height; public: double getVolume(void) { return length * breadth * height; } void setLength( double len ) { length = len; } void setBreadth( double bre ) { breadth = bre; } void setHeight( double hei ) { height = hei; } Box operator+(const Box& b) { Box box; box.length = this->length + b.length; box.breadth = this->breadth + b.breadth; box.height = this->height + b.height; return box; } }; int main( ) { Box Box1; Box Box2; Box Box3; double volume = 0.0; Box1.setLength(6.0); Box1.setBreadth(7.0); Box1.setHeight(5.0); Box2.setLength(12.0); Box2.setBreadth(13.0); Box2.setHeight(10.0); volume = Box1.getVolume(); cout << "Volume of Box1 : " << volume <<endl; volume = Box2.getVolume(); cout << "Volume of Box2 : " << volume <<endl; Box3 = Box1 + Box2; volume = Box3.getVolume(); cout << "Volume of Box3 : " << volume <<endl; return 0; }
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How to declare operator function?
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <string> using namespace std; int main () { string str ("Ubuntu"); cout << str.capacity(); cout << str.max_size(); return 0; }
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the use of functor?
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; void duplicate (int& a, int& b, int& c) { a *= 2; b *= 2; c *= 2; } int main () { int x = 1, y = 3, z = 7; duplicate (x, y, z); cout << x << y << z; return 0; }
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> using namespace std; int main() { int a = 20; int b = 10; int c = 15; int d = 5; int e; e = a + b * c / d; cout << e << endl ; return 0; }
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which is used to tell the computer that where a pointer is pointing to?
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following C++ code? #include <iostream> #include <cmath> using namespace std; class Complex { private: double real; double imag; public: Complex(double r = 0.0, double i = 0.0) : real(r), imag(i) {} double mag() { return getMag(); } operator double () { return getMag(); } private: double getMag() { return sqrt(real * real + imag * imag); } }; int main() { Complex com(3.0, 4.0); cout << com.mag(); cout << com; return 0 }
✓ Link copied to clipboard
Continue Your Practice
Next Practice Set → Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡 Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.