logo

UTK Notes


Clicker Questions - 13-Classes

Behold the declaration of the MyClass class below. Please answer the following true/false questions:

1
2
3
4
5
6
7
8
9
10
11
12
13
/*  1 */ class MyClass {
/*  2 */ public:
/*  3 */    MyClass();
/*  4 */    MyClass *Copy();
/*  5 */    MyClass(const MyClass &mc);
/*  6 */    void A(Otherclass &s) const;
/*  7 */    void B(Otherclass &s);
/*  8 */    void C(Otherclass &s) const;
/*  9 */    void D(const Otherclass &s);
/* 10 */    int F;
/* 11 */ protected:
/* 12 */    vector <int> v;
/* 13 */ };

A. The copy constructor is declared on line 3.

Answer False

B. The copy constructor is declared on line 4.

Answer False

C. The copy constructor is declared on line 5.

Answer True

D. The method A() cannot change change s.

Answer False

E. The method B() cannot change change s.

Answer False

F. The method C() cannot change change s.

Answer False

G. The method D() cannot change change s.

Answer True

H. The method A() cannot change change v.

Answer True

I. The method B() cannot change change v.

Answer False

J. The method C() cannot change change v.

Answer False

K. The method D() cannot change change v.

Answer False

L. When you call A(), you will call Otherclass’ copy constructor.

Answer False

M. When you call B(), you will call Otherclass’ copy constructor.

Answer True

N. When you call A(), you will call Otherclass’ regular constructor.

Answer False

O. When you call B(), you will call Otherclass’ regular constructor.

Answer False

P. When A() returns, it will call the destructor for s.

Answer False

Q. When B() returns, it will call the destructor for s.

Answer True

R. This header won’t compile, because F should be protected.

Answer False

S. If x and y are declared as MyClass variables, I’m allowed to say “x=y, even though I didn’t declare an assignment overload.

Answer True

T. There is a memory leak, because there is no destructor to free up the memory corresponding to the variable v.

Answer False

U. If Copy() calls new, I should have a destructor that calls delete.

Answer False

No Class Stats, PDF Download