Computer Programming- 3

40 Questions | Total Attempts: 45

SettingsSettingsSettings
Please wait...
Computer Programming- 3

  Classes in C++  Declaration and implementation  Accessing class members. Access control modifiers   Constructors   Destructor   Self-reference   Modifiers: static, const, mutable, friend


Questions and Answers
  • 1. 
    Classes are defined in C++ using struc tor class keywords
    • A. 

      True

    • B. 

      False

  • 2. 
    A class is defined by: 
    • A. 

      A class name;

    • B. 

      A class name, data and function members

    • C. 

      A class name, data and function members, relationships with other classes.

  • 3. 
    A class can have only one instance.
    • A. 

      True

    • B. 

      False

  • 4. 
    • A. 

      Is a specific part of the source code

    • B. 

      Is the main() function in a programm

    • C. 

      Is unique in a programm

  • 5. 
    A name is defined in the global scope if
    • A. 

      Is defined in a namespace

    • B. 

      Is defined in the main() function;

    • C. 

      Is defined outside any function or namespace;

  • 6. 
    A global variable's scope:
    • A. 

      Starts from the line in which main is declared and ends at the end of file

    • B. 

      Starts from the declaration point and ends at the end of the file

    • C. 

      Is not hidden by names declared in functions

  • 7. 
    If we have a global v ariable: int x=3, and we declare a local variable: int x=2 int y=0 in a function which returns x+y our function will return:
    • A. 

      3+0

    • B. 

      2+0

    • C. 

      2+3+0

  • 8. 
    Knowing that  " : : " (the resolution operator() allows access to an identifier declared in a different scope or namespace what is the output of the following program: \include int x=4; void sum() { int x=3;int y=4; :: x=2; x=x+y; cout<< x; } int main() { cout<<"global  x is: "<<x; cout<<"local x is"<<sum();
    • A. 

      Global x is 4 local x is 3

    • B. 

      Global x is 2 local x is 3

    • C. 

      Global x is 2 local x is 7

  • 9. 
    Member functions of a class are implemented as any ordinary C function.
    • A. 

      True

    • B. 

      False

  • 10. 
    A member function is accesed from outside the class by fully qualifying the ________ resolution operator
  • 11. 
    A member function:
    • A. 

      Is a name introduced in the scope defined by its member class

    • B. 

      Defines an objects state

    • C. 

      Defines an objects behaviour

  • 12. 
    In C++ class members can be accesed using:
    • A. 

      ' . '

    • B. 

      ' . ' or ' -> '

    • C. 

      ' -> '

  • 13. 
    Data hiding principle is implemented in C++ by 
    • A. 

      Defining various levels of access

    • B. 

      Polymorpish

    • C. 

      Inheritance

  • 14. 
    Data hiding principle is implemented in C++ by  defining various levels of access for class members. These are
    • A. 

      Private, public and protected

    • B. 

      Private and protected

    • C. 

      Private and public

  • 15. 
    Access levels: members declared private are accesible to:
    • A. 

      Member functions

    • B. 

      Friend functions

    • C. 

      Derived classes methods

    • D. 

      Any outside call

  • 16. 
    Access levels: members declared protected are accesible to:
    • A. 

      Member functions

    • B. 

      Friend functions

    • C. 

      Derived classes methods

    • D. 

      Any outside call

  • 17. 
    Access levels: members declared public are accesible to:
    • A. 

      Member functions

    • B. 

      Friend functions

    • C. 

      Derived classes methods

    • D. 

      Any outside call

  • 18. 
    The scope of an acces specificator lasts until another specificator  or the end of class definition is encountered
    • A. 

      True

    • B. 

      False

  • 19. 
    A member function may have more than one implementation 
    • A. 

      True

    • B. 

      False

  • 20. 
    • A. 

      Are not used to initialize objects

    • B. 

      Is a member function of a class

    • C. 

      Is not a member function of a class

    • D. 

      Its role is to initialise a classes instances/ objects

    • E. 

      Has the same name as the class

    • F. 

      Has the same name as the class with a tilda sign in front

    • G. 

      Has no return value

    • H. 

      Can be automatically generated by the compiler

    • I. 

      Can have pointers assigned to it

  • 21. 
    • A. 

      Used to release the class instances from the memory

    • B. 

      Is a member function of a class

    • C. 

      Is not a member function of a class

    • D. 

      Its role is to initialise a classes instances/ objects

    • E. 

      Has the same name as the class

    • F. 

      Has the same name as the class with a tilda sign in front

    • G. 

      Has no return value

    • H. 

      Take no arguments

    • I. 

      Can have pointers assigned to it

  • 22. 
    • A. 

      True

    • B. 

      False

  • 23. 
    A class can have more than one destructor but at most one constructor
    • A. 

      True

    • B. 

      False

  • 24. 
    • A. 

      A constant

    • B. 

      A variable

    • C. 

      Part of the class

    • D. 

      Not part of an object

    • E. 

      Part of an object

    • F. 

      Global variable

    • G. 

      Local variable

    • H. 

      Accesible only in the scope of the class

  • 25. 
    • A. 

      True

    • B. 

      False