C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 4)
4.
Which of the following is not the member of class?
Static function
Friend function
Const function
Virtual function
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
42 comments Page 1 of 5.

Amruta said:   1 decade ago
In a class, the private data can be accessed only by the public member function of that class. c++ provides a mechanism in which a non member can have access to the private member of a class. This is achieved by the non_member function "friend" to the class, whose private data can be accessed.

Smarak said:   1 decade ago
What is const function?
(1)

Srikanth said:   1 decade ago
A const function is one, which doesn't allow any modification or change its instance variable's data (member data).

Selvakumar said:   1 decade ago
What is virtual function ?

Kavita said:   1 decade ago
I agree with Amruta and virtual function is used for dynamic binding. If a virtual function is defined in the base class, it need not be necessarily redefined in the derived class. In such cases, class will invoke the base function.

Maha said:   1 decade ago
Why we are using virtual function in dynamic binding ?

Mohamed Rafeek said:   1 decade ago
In a class, the private data can be accessed only by the public member function of that class. C++ provides a mechanism in which a non member can have access to the private member of a class. This is achieved by the non_member function "friend" to the class, whose private data can be accessed.

Yogesh said:   1 decade ago
Virtual function can be used in derived class.

Sandesh said:   1 decade ago
A const member function cannot modify any of the data members of its class. This is used by programmers to prevent accidental modification of data members.

One more thing is that const memb function can modify only those data members that are declared as mutable.

Shruti Ganesh said:   1 decade ago
A class can have different types of MEMBER functions or methods. These can be static, virtual or constant.

These are functions of the class and belong to the class. However, a friend function is one such type of function which can access the private data members of a class and is not a MEMBER function.

Why do we need them? 'cause there are times when you need to access private data members with an external function. Using too many friend functions disintegrates the privacy of the object. They should be used only when necessary.


Post your comments here:

Your comments will be displayed after verification.