Question Paper C++ | PDF | Class (Computer Programming) | Method (Computer Programming)
100% found this document useful (1 vote)
165 views

Question Paper C++

The document contains 20 multiple choice questions related to classes in C++. Some questions ask about class member access, defining member functions, passing variables to functions, nested classes, object references, access specifiers, class members like data and functions, and dynamic memory allocation of class objects.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
165 views

Question Paper C++

The document contains 20 multiple choice questions related to classes in C++. Some questions ask about class member access, defining member functions, passing variables to functions, nested classes, object references, access specifiers, class members like data and functions, and dynamic memory allocation of class objects.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Q.

1
class Test
{
int x;
};
int main()
{
Test t;
cout << t.x;
return 0;
}

A. 0 B. Garbage Value C. Compiler Error

Q.2
#include <iostream>
class Test
{
public:
int i;
void get();
};
void Test::get()
{
cout << "Enter the value of i: ";
cin >> i;
}
Test t; // Global object
int main()
{
Test t; // local object
t.get();
cout << "value of i in local t: "<<t.i<<'n';
::t.get();
cout << "value of i in global t: "<<::t.i<<'n';
return 0;
}

A. Compiler Error: Cannot have two objects with same class name
B. Compiler Error in Line "::t.get();"
C. Compiles and runs fine

Q.3 A member function can always access the data in __________ , (in C++).

A. the class of which it is member B. the object of which it is a member


C. the public part of its class D. the private part of its class

Q.4 Which of the following cannot be passed to a function in C++ ?


A. Constant B. Structure C. Array D. Header File

Q.5 It is possible to define a class within a class termed as nested class. There are _____ types of
nested classes.

A. 2 B. 3 C. 4 D. 5

Q. 6 When one object reference variable is assigned to another object reference variable then

A. a copy of the object is created.


B. a copy of the reference is created.
C. a copy of the reference is not created.
D. it is illegal to assign one object reference variable to another object reference variable.

Q. 7 Which of the following is not a member of class?

A. Static function B. Friend function C. Const function


D. Virtual function

Q. 8 Which type of Access Specifier class data member number is?


//a simple class
class test_example
{
int number;
};

A. Private B. Public C. Protected D. Default

Q. 9 Which variable(s) is/are accessible in main() function?


class sample
{
private:
int x;
public:
int z;
}

A. x B. z C. x and z D. None of these

Q.10 A C+++ class contains...

A. Member Function B. Data Members C. Both 1 and 2


D. Customize main () function

Q.11 Where a class member function can be defined?

A. Inside the class definition B. Outside the class definition


C. Both A and B D. None of these
Q.12 Which of the following two entities (reading from Left to Right) can be connected by the dot
operator?

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.

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

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.

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

A. Friend Functions B. Object C. Member Functions


D. Member Variables

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

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.

Q.16 Which is used to define the member of a class externally?

A. : B. : : C. # D. none of the mentioned

Q. 17 Which of the following is a valid class declaration?

A. class A { int x; }; B. class B { }


C. public class A { } D. object A { int x; };

Q. 18 The fields in the class in c++ program are by default

A. protected B. private C. public D. none of the mentioned

Q. 19 Which operator is used to allocate an object dynamically of a class in C++?

A. Scope resolution operator B. Conditional operator


C. New operator D. Membership access

Q.20 In C++ programming, cout is a/an

A. Function B. Operator C. Object D. macro

You might also like