OOP Quiz3


1. Classes with methods that are declared but not implemented are called
virtual classes.
friend classes.
abstract classes.
base classes.

2. Assume a class C with objects obj1, obj2 and obj3. For the statement       [ref 1]
     obj3 = obj1 – obj2;
to work correctly, the overloaded subtraction operator must
take two arguments.
return a value.
create a named temporary object.
be declared as protected.

3. When an arithmetic assignment operator is overloaded, the result    [ref 1]
goes in the object to the right of the operator.
goes in the object to the left of the operator.
goes in the object of which the operator is a member.
must be returned.

4. To convert from a user-defined class to a primitive type, one would most likely use    [ref 1]
a built-in conversion function.
a one-argument constructor.
an overloaded = operator.
a conversion function that is a member of the class.

5.  Consider the case where the access keyword (i.e. public, protected or private) is not specified in declaring a base class. What is the default access of the variables and member functions in a derived class? [ref 2]
Variables are private and member functions are public.
Both variables and member functions are public.
Both variables and member functions are private.
The base class will not compile.

6. What is the main purpose of an abstract class?       [ref 2]
Abstract classes force programmers to write derived classes that implement the pure virtual member functions in the base class.
By casting a derived class pointer to the base class type, the developer can call virtual member functions.
You can create an instance of the base class and call the derived class by using the virtual functions.
You can call a pure virtual member function of the base class from the derived class without casting.

7. Consider the following program:
     #include <iostream.h>
  class Cat {public:
     void show() {cout << “\nThis is class Cat”;}
  };
  class Fish {public:
     void show() {cout << “\nThis is class Fish”;}
  };
  class CatFish: public Cat, public Fish{
  };

  int main(){
     CatFish Obj;
     Obj.show();
     return 0;
  }
Which of the following statements is true for the above program?
The program will compile and execute.
Class CatFish is undefined.
The program will result in compilation error because the line Objc.show(); is ambiguous.
None of the above.

8. Which of the following statements is true for the above program?
The context here is multiple inheritance, so the program is valid.
The program is not correct and one remedy is to rewrite Obj.show as Obj.Cat::show()orObj.Fish::show()in the main function.
The only way around the error is to rename the functions.
None of the above.

9. Consider the following program [ref 4]
  #include<iostream.h>
  class XYZ {private:
    int value;
  public:
    XYZ()          {value = 0;}
    XYZ(int i = 0) {value = i;}
  };
  int main() {
     XYZ obj;
  }
 In the above program:
the  constructor with no arguments is invoked.
the constructor with one argument is invoked.
the compiler will give an error.
none of the constructors is invoked.

10.  Consider  the following code. [ref 3]
     class A {public:
      int x;
      A() {x = 0;}
   };
   class B : public A {
   };
   class C : public A {
   };
   class D : public C, public B {
   };
   int main () {
       D obj;
   }
There is a misplaced punctuation mark.
Two classes cannot be derived from the same base class.
Empty classes are not allowed.
The program is trivial but fine.


Your Quiz Score is