logo
  • Home
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Contact

C++ Multiple Choice Questions | MCQs | Quiz

C++ Interview Questions and Answers
Pratice C++ questions and answers for interviews, campus placements, online tests, aptitude tests, quizzes and competitive exams.

Get Started

•   Types
•   Booleans
•   Character Types
•   Integer Types
•   Floating Point Types
•   Sizes
•   Void
•   Enumerations
•   Declaration
•   Pointers
•   Arrays
•   Pointers into Arrays
•   Constants
•   References
•   Pointer to Void
•   Structures
•   Operators
•   Statements
•   Comments & Indentation
•   Function Declarations
•   Argument Passing
•   Value Return
•   Overloaded Function
•   Default Arguments
•   Unspecified Arguments
•   Pointer to Function
•   Macros
•   Modularization
•   Namespaces
•   Exceptions
•   Linkage
•   Header Files Usage
•   Classes
•   User Defined Types
•   Objects
•   Operator Functions
•   Complex Number Type
•   Conversion Operators
•   Friends
•   Large Objects
•   Essential Operators
•   Subscripting
•   Function Call
•   Dereferencing
•   Increment & Decrement
•   String Class
•   Derived Classes
•   Abstract Classes
•   Class Hierarchies
•   Abstract Classes
•   Simple String Template
•   Function Templates
•   Policy Usage Template
•   Specialization
•   Derivation & Templates
•   Error Handling
•   Grouping of Exceptions
•   Catching Exceptions
•   Resource Management
•   Exceptions Not Errors
•   Exception Specifications
•   Uncaught Exceptions
•   Exceptions & Efficiency
•   Error Handling Alternatives
•   Standard Exceptions
•   Class Hierarchies
•   Multiple Inheritance
•   Access Control
•   Run Time Type
•   Pointers to Members
•   Free Store
•   Standard Library Design
•   Container Design
•   Vector
•   Sequences
•   Sequence Adapters
•   Associative Containers
•   Almost Containers
•   Defining a New Container
•   Library Algorithms
•   Sequences / Containers
•   Function Objects
•   Nonmodifying Algorithms
•   Modifying Algorithms
•   Stored Sequences
•   Heaps
•   Min and Max
•   Permutations
•   C Style Algorithms
•   Iterators & Sequences
•   Checked Iterators
•   Allocators
•   String Characters
•   Basic String
•   C Standard Library
•   Output Stream
•   Input Stream
•   Formatting
•   File & String Streams
•   Buffering
•   Locale
•   C Input Output
•   Numeric Limits
•   Mathematical Functions
•   Vector Arithmetic
•   Numeric Algorithms
•   Random Numbers

Best Reference Books

C++ Books
« Prev Page
Next Page »

C++ Programming Questions and Answers – Objects

Posted on November 13, 2012 by Manish
This section on C++ quiz focuses on “Objects”. One shall practice these quizzes to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ quiz comes with detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ quiz on “Objects” along with answers, explanations and/or solutions:

1. Where does the object is created?
a) class
b) constructor
c) destructor
d) attributes
View Answer

Answer: a
Explanation: In class only all the listed items except class will be declared.

2. How to access the object in the class?
a) scope resolution operator
b) ternary operator
c) direct member access operator
d) none of the mentioned
View Answer

Answer: c
Explanation: Objects in the method can be accessed using direct member access operator which is (.).

3. Which of these following members are not accessed by using direct member access operator?
a) public
b) private
c) protected
d) both private & protected
View Answer

Answer: d
Explanation: Because of the access given to the private and protected, We can’t access them by using direct member access operator.

4. What is the output of the following program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     class Box
  4.     {
  5.         public :
  6.         double length;
  7.         double breadth;
  8.         double height;
  9.     };
  10.     int main( )
  11.     {
  12.         Box Box1;
  13.         double volume;
  14.         Box1.height = 5;
  15.         Box1.length = 6;
  16.         Box1.breadth = 7.1;
  17.         volume = Box1.height * Box1.length * Box1.breadth;
  18.         cout << "Volume of Box1 : " << volume <<endl;
  19.         return 0;
  20.     }

a) 210
b) 213
c) 215
d) 217
View Answer

Answer: b
Explanation: In the above program, we are calculating the area of the cube by using the cube formula
Output:
$ g++ obj1.cpp
$ a.out
213

5. What is the output of the program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     class Rect
  4.     {
  5.         int x, y;
  6.         public:
  7.         void set_values (int,int);
  8.         int area ()
  9.         {
  10.             return (x * y);
  11.         }
  12.     };
  13.     void Rect::set_values (int a, int b) 
  14.     {
  15.         x = a;
  16.         y = b;
  17.     }
  18.     int main ()
  19.     {
  20.         Rect recta, rectb;
  21.         recta.set_values (5, 6);
  22.         rectb.set_values (7, 6);
  23.         cout << "recta area: " << recta.area();
  24.         cout << "rectb area: " << rectb.area();
  25.         return 0;
  26.     }

a) recta area: 30 rectb area: 42
b) recta area: 20 rectb area: 34
c) recta area: 30 rectb area: 21
d) none of the mentioned
View Answer

Answer: a
Explanation: We are calculating the area of rectangle by two objects.

6. Pick out the other definition of objects.
a) member of the class
b) associate of the class
c) attribute of the class
d) instance of the class
View Answer

Answer: d
Explanation: None.

7. How many objects can present in a single class?
a) 1
b) 2
c) 3
d) as many as possible
View Answer

Answer: d
Explanation: Because a class may contain any number of objects according to it’s compliance.

8. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     class sample
  4.     {
  5.         private:
  6.         int var;
  7.         public:
  8.         void input()
  9.         {
  10.            cout << var;
  11.         }
  12.         void output()
  13.         {
  14.            cout << "Variable entered is ";
  15.            cout << var << "\n";
  16.         }
  17.     };
  18.     int main()
  19.     {
  20.         sample object;
  21.         object.input();
  22.         object.output();
  23.         object.var();
  24.         return 0;
  25.     }

a) Enter an integer 5
Variable entered is 5
b) Runtime error
c) Error
d) None of the mentioned
View Answer

Answer: c
Explanation: While using private member, you can’t access it variable.

9. Which special character is used to mark the end of class?
a) ;
b) :
c) #
d) $
View Answer

Answer: a
Explanation: None.

10. What is the output of this program?

  1.     #include <iostream>
  2.     using namespace std;
  3.     class number
  4.     {
  5.         int i;
  6.         public:
  7.         int geti();
  8.         void puti(int j);
  9.     };
  10.     int number::geti()
  11.     {
  12.         return i;
  13.     }
  14.     void number::puti(int j)
  15.     {
  16.         i = j;
  17.     }
  18.     int main()
  19.     {
  20.         number s;
  21.         s.puti(10);
  22.         cout << s.geti( );
  23.         return 0;
  24.     }

a) 10
b) 11
c) 20
d) 22
View Answer

Answer: a
Explanation: We are getting the number and copying it to j and printing it.
Output:
$ g++ obj2.cpp
$ a.out
10

Sanfoundry Global Education & Learning Series – C++ Programming Language.

Here’s the list of Best Reference Books in C++ Programming Language.

To practice all features of C++ programming language, here is complete set on 1000+ Multiple Choice Questions and Answers on C++.

« Prev Page - C++ Programming Questions and Answers – User Defined Types
» Next Page - C++ Programming Questions and Answers – Operator Functions
« C++ Programming Questions and Answers – User Defined Types
C++ Programming Questions and Answers – Operator Functions »

Deep Dive @ Sanfoundry:

  1. C Programming Examples on Data-Structures
  2. Data Structure Questions and Answers
  3. C++ Programming Examples on Data-Structures
  4. Java Programming Examples on Data-Structures
  5. C++ Questions and Answers
  6. C# Programming Examples on Arrays
  7. R Programming Questions and Answers
  8. Ruby Programming Questions and Answers
  9. C# Basic Programming Examples
  10. Object Oriented Programming Questions and Answers
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below:
LinkedIn | Facebook | Twitter | Google+

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
TOS & Privacy
Jobs
Bangalore Training
Online Training
SAN Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry