Home - Cpp Programming - Objects And Classes

Objects And Classes Online Exam Quiz

Important questions about Objects And Classes. Objects And Classes MCQ questions with answers. Objects And Classes exam questions and answers for students and interviews.

1. What does a class hierarchy depict?

Options

A : It shows the relationships between the classes in the form of an organization chart.

B : It describes "has a" relationships.

C : It describes "kind of" relationships.

D : It shows the same relationship as a family tree.

2. Which of the following statements is correct about the program given below? class CuriousTab { public: static void MyFunction(); }; int main() { void(*ptr)() = &CuriousTab::MyFunction; return 0; }

Options

A : The program reports an error as pointer to member function cannot be defined outside the definition of class.

B : The program reports an error as pointer to static member function cannot be defined.

C : The program reports an error as pointer to member function cannot be defined without object.

D : The program reports linker error.

3. Which of the following also known as an instance of a class?

Options

A : Friend Functions

B : Object

C : Member Functions

D : Member Variables

4. Which of the following can be overloaded?

Options

A : Object

B : Functions

C : Operators

D : Both B and C

5. What happens when we try to compile the class definition in following code snippet? class Birds {}; class Peacock : protected Birds {};

Options

A : It will not compile because class body of Birds is not defined.

B : It will not compile because class body of Peacock is not defined.

C : It will not compile because a class cannot be protectedly inherited from other class.

D : It will compile succesfully.

6. Which of the following two entities (reading from Left to Right) can be connected by the dot operator?

Options

A : A class member and a class object.

B : A class object and a class.

C : A class and a member of that class.

D : A class object and a member of that class.

7. Which of the following is the only technical difference between structures and classes in C++?

Options

A : Member function and data are by default protected in structures but private in classes.

B : Member function and data are by default private in structures but public in classes.

C : Member function and data are by default public in structures but private in classes.

D : Member function and data are by default public in structures but protected in classes.

8. Which of the following means "The use of an object of one class in definition of another class"?

Options

A : Encapsulation

B : Inheritance

C : Composition

D : Abstraction

9. Which of the following can access private data members or member functions of a class?

Options

A : Any function in the program.

B : All global functions in the program.

C : Any member function of that class.

D : Only public member functions of that class.

10. Which of the following keywords is used to control access to a class member?

Options

A : Default

B : Break

C : Protected

D : Asm

2. Which of the following statements is incorrect?

Options

A : Friend keyword can be used in the class to allow access to another class.

B : Friend keyword can be used for a function in the public section of a class.

C : Friend keyword can be used for a function in the private section of a class.

D : Friend keyword can be used on main() .

3. Constructor is executed when _____.

Options

A : an object is created

B : an object is used

C : a class is declared

D : an object goes out of scope.

4. Which of the following statements is correct when a class is inherited privately?

Options

A : Public members of the base class become protected members of derived class.

B : Public members of the base class become private members of derived class.

C : Private members of the base class become private members of derived class.

D : Public members of the base class become public members of derived class.

5. How many objects can be created from an abstract class?

Options

A : Zero

B : One

C : Two

D : As many as we want

7. What will be the output of the following program? #include<iostream.h> class India { public: struct CuriousTab { int x; float y; void Function(void) { y = x = (x = 4*4); y = --y * y; } void Display() { cout<< y << endl; } }B; }I; int main() { I.B.Display(); return 0; }

Options

A : 0

B : 1

C : -1

D : Garbage value

8. What will be the output of the following program? #include<iostream.h> #include<string.h> class CuriousTab { int val; public: void SetValue(char *str1, char *str2) { val = strcspn(str1, str2); } void ShowValue() { cout<< val; } }; int main() { CuriousTab objCuriousTab; objCuriousTab.SetValue((char*)"India", (char*)"CuriousTab"); objCuriousTab.ShowValue(); return 0; }

Options

A : 2

B : 3

C : 5

D : 8

9. What will be the output of the following program? #include<iostream.h> class Point { int x, y; public: Point(int xx = 10, int yy = 20) { x = xx; y = yy; } Point operator + (Point objPoint) { Point objTmp; objTmp.x = objPoint.x + this->x; objTmp.y = objPoint.y + this->y; return objTmp; } void Display(void) { cout<< x << " " << y; } }; int main() { Point objP1; Point objP2(1, 2); Point objP3 = objP1 + objP2; objP3.Display(); return 0; }

Options

A : 1 2

B : 10 20

C : 11 22

D : Garbage Garbage

5. What will be the output of the following program? #include<iostream.h> class Tab { public: int x; }; int main() { Tab *p = new Tab(); (*p).x = 10; cout<< (*p).x << " " << p->x << " " ; p->x = 20; cout<< (*p).x << " " << p->x ; return 0; }

Options

A : 10 10 20 20

B : Garbage garbage 20 20

C : 10 10 Garbage garbage

D : Garbage garbage Garbage garbage

7. What will be the output of the following program? #include<iostream.h> class CuriousTab { static int count; public: static void First(void) { count = 10; } static void Second(int x) { count = count + x; } static void Display(void) { cout<< count << endl; } }; int CuriousTab::count = 0; int main() { CuriousTab :: First(); CuriousTab :: Second(5); CuriousTab :: Display(); return 0; }

Options

A : 0

B : 5

C : 10

D : 15

10. What will be the output of the following program? #include<iostream.h> class CuriousTabTeam { int x, y; public: CuriousTabTeam(int xx) { x = ++xx; } void Display() { cout<< --x << " "; } }; int main() { CuriousTabTeam objBT(45); objBT.Display(); int *p = (int*)&objBT; *p = 23; objBT.Display(); return 0; }

Options

A : 45 22

B : 46 22

C : 45 23

D : 46 23

Cpp Programming more Online Exam Quiz

Copyright © 2021
Exam-GK-MCQ-Questions.Com | Contact Us | Privacy Policy | Terms of Use | Sitemap | 0.018691062927246