Class and Objects

  1. C++  supports  both  classes and structures.    Which of the following statements is FALSE in respect of both of them?
    • Both can have variables and functions as members.
    • In both, the members are private by default.
    • They support inheritance.
    • Their names can be used like any other types names.
  2. In a class definition, the members declared as private are accessible
    • only to the public functions of the class
    • to any function in the program
    • only to functions declared as private
    • to all member functions of the class
  3. By default, member functions of a class become
    • private
    • public
    • protected
    • inline
  4. In a class, a member declared as public is accessible
    • only to public members of the class
    • only to member functions of the
    • class to any function in the program
    • without using objects of the class
  5. The dot operator is used to connect
    • a class and a member of that class
    • a class object and a member of that class
    • a class object and any function
    • a class and an object of that class
  6. Declaration of members as private in C++ enables it to implement the concept
    • polymorphism
    • modularity
    • abstraction
    • encapsulation
  7. Listed below are some of the possible characteristics of member functions. Which  one of them is NOT TRUE?
    • All the member functions should be defined within the class itself
    • Several different classes can use the same function name
    • Member functions can access the private members of the class.
    • A member function can call another member function directly without using the dot operator.
  8. State which of the following is false with respect to classes:
    • They permit data to be hidden from other parts of the program
    • They can directly map objects in the real world
    • They bring together all attributes of an entity in one place
    • They are removed from memory when not in use
  9. Which one of the following statements is FALSE?
    • A member function defined outside can be made inline using the qualifier inline.
    • A member function can be called by using its name alone inside another member function.
    • An object of a class can access all its member functions whether they are declared private or public.
    • A private member function can only be called by another function that is a member of its class.
  10. When called by its object, a member function declared as const
    • can modify data of only const members.
    • can modify data of only non-const members.
    • can modify data of all members.
    • cannot alter any data in the class.
  11. A member function declared as static
    • can have access to only other static members of its class
    • must be called using only the objects of its class
    • can be called using only its class name
    • can have access to all members in the same class
  12. Which one of the following statements is not true for a member function declared as friend?
    • It can be invoked like a normal function without help of any object.
    • It cannot access the members of the class directly.
    • It cannot have objects as arguments.
    • It cannot be called using the objects of its class.
  13. Which of the following is TRUE about static member variable of a class?
    • Each object creates its own copy.
    • It is visible only within the class.
    • It can be initialized whenever necessary.
    • It cannot be assigned any initial value at the time of definition.
  14. Which one of the following is TRUE while passing objects as function arguments?
    • A copy of the entire objects can be passed.
    • Only the address of the object can be passed.
    • A nonmember function can use objects as its arguments.
    • All of the above.
  15. Which one of the following is FALSE?
    • The address of a class member can be assigned to a pointer variable.
    • A class can be defined inside a function.
    • When making a member function const, the qualifier const must be used in both declaration and definition.
    • None of the above

Answers:

  1. In both, the members are private by default.
  2. to all member functions of the class
  3. private
  4. to any function in the program
  5. a class object and a member of that class
  6. encapsulation
  7. All the member functions should be defined within the class itself
  8. They bring together all attributes of an entity in one place
  9. An object of a class can access all its member functions whether they are declared private or public
  10. cannot alter any data in the class.
  11. can have access to only other static members of its class
  12. It can be invoked like a normal function without help of any object.
  13. It can be initialized whenever necessary.
  14. All of the above.
  15. When making a member function const, the qualifier const must be used in both declaration and definition.

Related posts