Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
Class Quiz
CMPT 135
Spring 2019
What is the difference between a struct and a
class?
a) nothing: they are completely the same
b) a struct cannot have methods
c) a struct cannot have a private part
d) a struct is public by default, and a class is private by default
e) none of the above
What is the name of the pointer that C++ adds
to each object that points to the object itself?
a) this
b) that
c) self
d) whatever the name of the class is
Which one of the these is true of the code on
the right?
a) B is derived from A
b) B inherits from A
c) B is a subclass of A
d) A is a superclass of B
e) all of the above
f) a), b) and c) only
class A {
// …
};
class B : public A {
// …
};
What is the name for a destructor in a class
called File?
a) File
b) ~File
c) delete
d) destroy
e) none of the above
When is a destructor called?
a) whenever the programmer calls it
b) when the object it’s part of is deleted
c) both a) and b)
d) none of the above
What does “= 0” a the end of a method mean?
a) the method cannot be implemented by any method, even in inheriting
classes
b) the method has no implementation in this class
c) it returns 0 by default
d) none of the above
What is a virtual method?
a) an unimplemented method
b) a method that does not change the state of its object
c) a method that can be re-implemented in an inheriting class
d) none of the above
What is an abstract base class?
a) a class where the methods are virtual and “= 0”
b) a class where the methods are virtual, but not necessarily “= 0”
c) a class with no methods
d) a class with no constructors
Which one of the following is true?
a) abstract base classes should never declare a virtual destructor
b) abstract base classes should always declare a virtual destructor
c) destructors are virtual by default
d) destructors cannot be declared virtual
What is a const method?
a) a method that cannot be over-ridden by a method in an inheriting class
b) a method that returns a constant value
c) a method that does not change the state of its object
d) none of the above
Which one of the following is true?
a) both getters and setters should be declared const
b) getters should be declared const
c) setters should be declared const
d) neither setters nor getters should be declared const
Which one of the following is true?
a) a class can inherit from at most one other class
b) a class must inherit from exactly one other class
c) a class can inherit from more than one other class
d) none of the above are true
Thanks for playing!