Filters
Question type

Study Flashcards

Who can access private data in a class?


A) members of the class
B) friends of the class
C) everyone
D) B and C
E) no one

Correct Answer

verifed

verified

The assignment operator must be a _________ of the class.

Correct Answer

verifed

verified

How many parameters are there in a binary operator implemented as a friend?


A) 0
B) 1
C) 2
D) as many as you need

Correct Answer

verifed

verified

An overloaded extraction or insertion operator should return ___________

Correct Answer

verifed

verified

a referenc...

View Answer

Friend functions may directly modify or access the private data members.

Correct Answer

verifed

verified

The copy constructor for a class is called


A) when an object of the class is passed by value to a function.
B) when an object of the class is initialized by another object of the class
C) when a function returns an object of the class
D) all of the above

Correct Answer

verifed

verified

An operator that expects two parameters is called a ________ operator.

Correct Answer

verifed

verified

Write the function declaration for a copy constructor for a class named myClass

Correct Answer

verifed

verified

myClass co...

View Answer

Operators must be friends of the class.

Correct Answer

verifed

verified

The destructor for a class is called


A) explicitly from the main program
B) when the class is instantiated
C) when the object of the class goes out of scope
D) Only at the end of main

Correct Answer

verifed

verified

If obj1 and obj2 are both objects of a class that uses dynamic memory allocation, but the class does not have an assignment operator, what happens if you execute the following code? Obj1=obj2;


A) A syntax error occurs, you can not assign one object to another object without the = operator
B) A run-time error occurs, because the C++ system does not know how to do the assignment.
C) The pointers) to the dynamically declared memory in obj2 are copied to the corresponding pointers in obj1.
D) There is a complete and independent copy of all the dynamic memory from obj2 to obj1

Correct Answer

verifed

verified

Which of the following operators can not be overloaded?


A) =
B) ==
C) .
D) []

Correct Answer

verifed

verified

If a given task being performed by a function involves more than one object, then that function should normally be a __________ function.

Correct Answer

verifed

verified

A friend function needs to be passed an object of the class. If the friend only needs to access the object, but not change its data members, then the object should be passed as _______________

Correct Answer

verifed

verified

a constant...

View Answer

Given the following class, which is the correct function header for the display function? Class Rational { Public: Rational) ; Rationalint numer, int denom) ; Rationalint whole) ; Int getNumerator) ; Int getDenominator) ; Friend void displayostream& out, const Rational& value) ; Private: Int numerator; Int denominator; };


A) friend void displayostream& out, const Rational& value)
B) void displayostream& out, const Rational& value)
C) void Rational::displayostream& out, const Rational& value)
D) friend void Rational::displayostream& out, const Rational& value)

Correct Answer

verifed

verified

An operator that expects only one parameter is called a ________ operator

Correct Answer

verifed

verified

Friend functions are members of the class.

Correct Answer

verifed

verified

Which of the following are valid declarations for an assignment operator for a class named myClass?


A) void friend operator = myClass& left, const myClass& source) ;
B) void operator = myClass& left, const myClass& source) ;
C) void friend operator = const myClass& source) ;
D) void operator = const myClass& source) ;

Correct Answer

verifed

verified

The following is a properly declared overloaded insertion operator for myClass. ostream& operator <<ostream &out, const myClass &obj);

Correct Answer

verifed

verified

Which of the following would be an appropriate function declaration to add two rational numbers?


A) void friend operator+ const Rational &left, const Rational &right) ;
B) void operatator+ const Rational &left, const Rational &right) ;
C) friend Rational operator+ const Rational &left, const Rational &right) ;
D) Rational operator+ const Rational &left, const Rational &right) ;

Correct Answer

verifed

verified

Showing 21 - 40 of 56

Related Exams

Show Answer