The document contains 12 multiple choice questions that assess knowledge of C++ concepts like classes, constructors, friend functions, and output. Key points covered include:
- Valid class declarations and differences between constructors and other member functions
- Parameters for default constructors and access specifiers for constructors
- Output of sample C++ code using static class members and friend functions
- Correct C++ variable types and meaning of expressions involving objects and members
- How reusability and inline functions are implemented in C++
The document contains 12 multiple choice questions that assess knowledge of C++ concepts like classes, constructors, friend functions, and output. Key points covered include:
- Valid class declarations and differences between constructors and other member functions
- Parameters for default constructors and access specifiers for constructors
- Output of sample C++ code using static class members and friend functions
- Correct C++ variable types and meaning of expressions involving objects and members
- How reusability and inline functions are implemented in C++
The document contains 12 multiple choice questions that assess knowledge of C++ concepts like classes, constructors, friend functions, and output. Key points covered include:
- Valid class declarations and differences between constructors and other member functions
- Parameters for default constructors and access specifiers for constructors
- Output of sample C++ code using static class members and friend functions
- Correct C++ variable types and meaning of expressions involving objects and members
- How reusability and inline functions are implemented in C++
The document contains 12 multiple choice questions that assess knowledge of C++ concepts like classes, constructors, friend functions, and output. Key points covered include:
- Valid class declarations and differences between constructors and other member functions
- Parameters for default constructors and access specifiers for constructors
- Output of sample C++ code using static class members and friend functions
- Correct C++ variable types and meaning of expressions involving objects and members
- How reusability and inline functions are implemented in C++
declaration? a) class A { int x; }; b) class B { } c) public class A { } d) object A { int x; }; 2. How constructors are different from other member functions of the class? a) Constructor has the same name as the class itself b) Constructors do not return anything c) Constructors are automatically called when an object is created d) All of the mentioned 3. How many parameters does a default constructor require? a) 1 b) 2 c) 0 d) 3 4. Under which acess specifier constructor should declared? a) Public b) Private c) Protected d) None of these 5- What will be the output of the following C++ code? #include <iostream> #include <string> 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; } a)1055 b) 555 c) 101010 d) 51010 6.Q.Which one is not a correct variable type in C++? A.float B.real C.int D.double 7.Q.An expression A.B in C++ means ____ A.A is member of object B B.B is member of Object A C.Product of A and B D.None of these 8.Q.Reusability of code in C++ is achieved through ____ A.Polymorphism B.Inheritance C.Encapsulation D.Both A and B 9.Q.In C++ Program, inline fuctions are expanded during ____ A.Run Time B.Compile Time C.Debug Time D.Coding Time 10. What is a friend function in C++? a) A function which can access all the private, protected and public members of a class b) A function which is not allowed to access any member of any class c) A function which is allowed to access public and protected members of a class d) A function which is allowed to access only public members of a class 11. What will be the output of the following C++ code? #include <iostream> #include <string> class Box { int capacity; public: Box(int cap) { capacity = cap; } friend void show(); }; void show() { Box b(10); cout<<"Value of capacity is:"<<b.capacity<<endl; } int main(int argc, char const *argv[]) { show(); return 0; } a) Value of capacity is: 10 b) Value of capacity is: 100 c) Error d) Segmentation fault 12. What will be the output of the following C++ code? #include <iostream> #include <string> class Box { int capacity; public: Box(int cap) { capacity = cap; } friend void show(); }; void Box::show() { Box b(10); cout<<"Value of capacity is:"<<b.capacity<<endl; } int main(int argc, char const *argv[]) { show(); return 0; } • a) Value of capacity is: 10 b) Value of capacity is: 100 c) Error d) Segmentation fault