350 Assignment 3
Compiles and runs fine
#include <iostream> class Test { public: int i; void get(); }; void Test::get() { std::cout << "Enter the value of i: "; std::cin >> i; } Test t; // Global object int main() { Test t; // local object t.get(); std::cout << "value of i in local t: "<<t.i<<'\n'; ::t.get(); std::cout << "value of i in global t: "<<::t.i<<'\n'; return 0; }
the class of which it is member
A member function can always access the data in __________ , (in C++).
8 4
Assume that an integer and a pointer each takes 4 bytes. Also, assume that there is no alignment in objects. Predict the output following program. #include<iostream> using namespace std; class Test { static int x; int *ptr; int y; }; int main() { Test t; cout << sizeof(t) << " "; cout << sizeof(Test *); }
true
Below is an example of creating an object of a class (True/False). int main() { Cellphone obj; return 0; }
2
It is possible to define a class within a class termed as nested class. There are _____ types of nested classes.
A non-zero value
Predict the output of following C++ program #include<iostream> using namespace std; class Empty {}; int main() { cout << sizeof(Empty); return 0; }
overrides
When a method in a subclass has the same name and type signatures as a method in the superclass, then the method in the subclass _____ the method in the superclass
copy of reference is created
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
header file
Which of the following cannot be passed to a function in C++ ? (A) Constant (B) Structure (C) Array (D) Header file
Composition is a strong type of association between two classes with full ownership
Which of the following is a correct statement? (A) Composition is a strong type of association between two classes with full ownership. (B) Composition is a strong type of association between two classes with partial ownership. (C) Composition is a weak type of association between two classes with partial ownership. (D) Composition is a weak type of association between two classes with strong ownership
friend function
Which of the following is not a member of class? (A) Static function (B) Friend function (C) Const function (D) Virtual function
2 3 4
Which of the following is not correct (in C++) ? 1. Class templates and function templates are instantiated in the same way 2. Class templates differ from function templates in the way they are initiated 3. Class template is initiated by defining an object using the template argument 4. Class templates are generally used for storage classes
virtual function can be static
Which of the following is not correct for virtual function in C++ ? (A) Must be declared in public section of class. (B) Virtual function can be static. (C) Virtual function should be accessed using pointers. (D) Virtual function is defined in base class. (A virtual function is a member function in the base class that we expect to redefine in derived classes.)
Objects of a class do not share non-static members. Every object has its own copy.
Which of the following is true? (A) All objects of a class share all data members of class (B) Objects of a class do not share non-static members. Every object has its own copy. (C) Objects of a class do not share codes of non-static methods, they have their own copy (D) None of the above
data members
Which of the following, in C++, is inherited in a derived class from base class ? (A) constructor (B) destructor (C) data members (D) virtual methods
Compiler Error
class Test { int x; }; int main() { Test t; cout << t.x; return 0; }