Suppose we\'ve defined a book class to include a setTitle method with a prototyp
ID: 3827480 • Letter: S
Question
Suppose we've defined a book class to include a setTitle method with a prototype: void setTitle(char *); Suppose further we have an instance of the book class named bookOne. Determine which of the following statements correctly invokes the setTitle method: a. title = bookOne.setTitle("Book One"); b. title - book.setTitle("Book One"); c. bookOne.setTitle("Book One"); d. book.setTitle("Book One"); Answer: _____. Let v be a static variable defined in a class called C a. v gets initialized every time an instance of C is created. b. v retains same value for all instances of C c. v can only be accessed by non-class functions d. None of the above Answer: _____Explanation / Answer
1. void setTitle(char*);
Determine which of the following statements correctly invokes the setTitle method:
a. title = ... //setTitle() is a void returning method so this is not the case.
b. title = ... //setTitle() is a void returning method so this is not the case.
c. bookOne.setTitle("Book One"); //bookOne is an object of type book, and is invoking
the member function setTitle. So, this is the correct answer.
d. book.setTitle("Book One"); //book is the name of a class, and is not allowed
to call instance methods.
So, the answer is c.
2. Let v be a static variable defined in a class called C.
a. v gets initialized every time an instance of C is created. //No.static variables are
independent of instances.
b. v retains same value for all instances of C. //Yes. a static variable is initialized
only once, and can be used any number of times, by any number of instances.
c. v can only be accessed by non-class functions. //No. It be accessed by members
even.
So, the answer is b.