C++ Midterm Flashcards
State the following C/C++ expression below abbreviates:
a[8] ______________
- (a + 8)
Expand the Acronym RTTI
Run time Type Identification
Briefly describe ‘reflection’ in java
The ability to learn at runtime the class to which an object belongs, and properties of that class. Basic tools: getClass(), instanceOf
T/F java allows multiple inheritance
F
T/F java does not allow pointer arithmetic
T
C allows branching into the middle of a block but c++ does not
F
in c++ an int must contain precisely 32 bits in binary
F
C++ allows the statement 17;
T
in C++ a struct can contain both fields and member functions
T
Java and C++ have precisely three access modes
F
the object class is inherited by each java class
T
Assume a class declared as class stuff { string a,b;} provide a single constructor for stuff which works as follows: the constructor can be called with two, one or zero parameters.
public stuff(string c = "", string d = ""){ a = c; b = d; }
Assume a class declared as class stuff { string a,b;} provide a copy constructor for this class which does not result in 'sharing' of the string value for the two copies
stuff(const staff &s) { stuff temp = new staff(); temp a = s *a; temp b = s *b; return temp;}
Assume a class ‘rational’ for rational number. Give two prototypes for an override of +, one a friend function, and the other not. Indicate how each is called by giving example code snippets.
friend rational operator + (rational r1, rational r2)
rational operator + (rational r)
first called by roat = r1 + r2; [r + (r1,r2)]
2nd called by roat = r1+(r2) [or r1+r2]
Suppose we have, assuming a rational number class,
const rational half = new rational (1,2);
Given the half is constant, what kind of messages can be sent to half? Indicate the syntax of a valid method being use this way.
Message must be “constant member function”
foo(___) const{____}