Paper Tayyari

Lecture 29: Friend Functions

MCQs, short and long questions from lecture 29.Lecture 29 ki MCQs, short aur long sawal.

11 MCQs · 2 short · 2 long questions · 11 MCQs from past papers11 MCQs · 2 short · 2 long sawal · 11 MCQs past papers se

Start mock testMock test shuru karein
DoneHal kiye 0/11
– correctsahi
1.
★ Final term 2017 (paper 1)

If a friend function outside the class declares itself friend of the class, this may violate the concept of ________.

  1. AEncapsulation and data accessing
  2. BEncapsulation and data hiding
  3. CFriend member functions of the class
  4. DInterface of the class

Friendship must be granted by the class; a function granting itself access would break encapsulation and data hiding.

2.
★ Final term 2017 (paper 1)

The prototype of friend function is written ________.

  1. ABefore the class definition
  2. BAs private member function
  3. CAnywhere inside the class definition
  4. DIn the main function

A friend declaration can appear anywhere in the class; access specifiers do not affect it.

3.
★ Final term 2017 (paper 2)

Friend class of the other class gets ______ access to ______.

  1. APartial, data member and member functions.
  2. BRead only, data member and member functions.
  3. CComplete, data members only.
  4. DComplete, all data members and member functions.

A friend class can access all private and protected members of the class that befriends it.

4.
★ Final term solved MCQs (Moaaz & Asad)

Which of the following statement is best regarding declaration of friend function?

  1. AFriend function must be declared after public keyword.
  2. BFriend function must be declared after private keyword.
  3. CFriend function must be declared at the top within class definition.
  4. DIt can be declared anywhere in class as these are not affected by the public and private keywords.

Access specifiers do not affect friend declarations, so they may appear anywhere in the class.

5.
★ Final term solved MCQs (Moaaz & Asad)

Like member functions, ______ can also access the private data members of a class.

  1. ANon-member functions
  2. BFriend functions
  3. CAny function outside class
  4. DNone of the given options

A friend function is granted access to the class's private members.

6.
★ Final term solved MCQs (Moaaz & Asad)

Friend function of a class is ______________ .

  1. AMember function
  2. BNon-member function
  3. CPrivate function
  4. DPublic function

A friend function is not a member of the class even though it has access to it.

7.
★ Final term solved MCQs (Moaaz & Asad)

Function implementation of friend function must be defined outside the class.

  1. ATrue
  2. BFalse

A friend function can also be defined inline inside the class body.

8.
★ Final term solved MCQs (Moaaz & Asad)

The prototype of friend functions must be written ____ the class and its definition must be written ____

  1. Ainside, inside the class
  2. Binside, outside the class
  3. Coutside, inside the class
  4. Doutside, outside the class

The friend declaration goes inside the class and the function is normally defined outside it.

9.
★ Final term solved MCQs (Moaaz & Asad)

A function can declare itself a friend of a class.

  1. ATrue
  2. BFalse

Friendship is granted by the class, not claimed by the function.

10.
★ Final term Fall 2005

A friend function of a class has access

  1. ATo all data member and functions of the class
  2. BOnly to other friend functions of the class
  3. COnly to private data of the class
  4. DOnly to public data of the class

A friend can use all members of the class, including private and protected ones.

11.
★ Final term Spring 2005

A friend function

  1. Amust be having a prototype with no arguments
  2. Bmust be invoked by the class that declares it a friend
  3. Cmust be invoked by an object of the class that declares it a friend
  4. Dcan access the private data of the class that declares it a friend

A friend is not a member but is allowed to use the class's private data.