Which member function can only be called by another function that is member of its class?

Which member function can only be called by another function that is member of its class?


22. 

Which of the following means "The use of an object of one class in definition of another class"?

A. Encapsulation
B. Inheritance
C. Composition
D. Abstraction

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.


23. 

Which of the following is the only technical difference between structures and classes in C++?

A. Member function and data are by default protected in structures but private in classes.
B. Member function and data are by default private in structures but public in classes.
C. Member function and data are by default public in structures but private in classes.
D. Member function and data are by default public in structures but protected in classes.

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.

4. 

Which of the following is not the member of class?

[A]. Static function
[B]. Friend function
[C]. Const function
[D]. Virtual function

Answer: Option B

Explanation:

No answer description available for this question.


Amruta said: (May 11, 2012)  
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: (May 12, 2012)  
What is const function?


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


Selvakumar said: (Jul 9, 2012)  
What is virtual function ?


Kavita said: (Jul 12, 2012)  
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: (Jul 19, 2012)  
Why we are using virtual function in dynamic binding ?


Mohamed Rafeek said: (Jul 31, 2012)  
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: (Aug 16, 2012)  
Virtual function can be used in derived class.


Sandesh said: (Aug 17, 2012)  
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: (Aug 22, 2012)  
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.


Abhishek Porwal said: (Aug 23, 2012)  
Private data member can acess out side the class with the help of friend function. (i.e) we can access the private data member of the base class in drived class so we use friend function.


Yogeshwar Bargal said: (Oct 6, 2012)  
I dont know what is cont class?


Shashi said: (Mar 17, 2013)  
A friend function is that function of the class which can access the private and public members of the class but it is not the member of the class. It is declared inside the class either in private or public.


Vani said: (Apr 25, 2013)  
What is virtual funtion?


Vidya V Nair said: (May 1, 2013)  
Virtual function means the function defined in a base class implemented by the child class and it is called at the run time.


Manisha said: (May 18, 2013)  
A virtual function is a member function that is declared within a base class and redefined by a derived class. To create virtual function, precede the function's declaration in the base class with the keyword virtual. When a class containing virtual function is inherited, the derived class redefines the virtual function to suit its own needs.

Base class pointer can point to derived class object. In this case, using base class pointer if we call some function which is in both classes, then base class function is invoked. But if we want to invoke derived class function using base class pointer, it can be achieved by defining the function as virtual in base class, this is how virtual functions support runtime polymorphism.

Consider following program code:

Class A
{
int a;
public:
A()
{
a = 1;
}
virtual void show()
{
cout <<a;
}
};

Class B: public A
{
int b;
public:
B()
{
b = 2;
}
virtual void show()
{
cout <<b;
}
};

int main()
{
A *pA;
B oB;
pA = &oB;
pA->show();
return 0;
}

Output is 2 since pA points to object of B and show() is virtual in base class A.


Saai said: (Sep 29, 2013)  
Can you explain the main function?


Shakti said: (Nov 22, 2013)  
What is the mean of 'pA->show() ;'. And how its work ?


Anjali said: (Mar 3, 2014)  
#include <iostream>

using namespace std;

class Box
{
double width;
public:
friend void printWidth( Box box );
void setWidth( double wid );
};

// Member function definition
void Box::setWidth( double wid )
{
width = wid;
}

// Note: printWidth() is not a member function of any class.
void printWidth( Box box )
{
/* Because setWidth() is a friend of Box, it can
directly access any member of this class */
cout << "Width of box : " << box.width <<endl;
}

// Main function for the program
int main( )
{
Box box;

// set box width without member function
box.setWidth(10.0);

// Use friend function to print the wdith.
printWidth( box );

return 0;
}


Datta Bachate said: (Mar 8, 2014)  
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.


Ankita said: (Jun 24, 2014)  
What is dynamic binding, static function, const function, virtual function?


Karthika said: (Sep 21, 2014)  
What is dynamic binding, static function, const function, virtual function?


Ashish Ranjan Shadangi said: (Feb 10, 2015)  
pA = &oB; means pA contains the address of oB. And pA->show will definitely show the output as 2.

So what is the requirement of show as virtual function?


Pooja said: (Mar 30, 2015)  
What is the friend function?


Raj said: (May 4, 2015)  
@Pooja.

Friend function can access the private & protected data of the parent class!

Normally, Other class couldn't able to access the private & protected data of a class.


Mahesh27 said: (May 27, 2015)  
What is this pointer?


Saddam Hossain Mondal said: (Aug 2, 2015)  
A function that has access to the private members of a class but is not itself a member of the class. An entire class can be a friend function of another class. A function that although not a member of a class is able to access the private members of that class.


Sabitha.R said: (Aug 27, 2015)  
Friend function is used in only public class.


N.Sivaraman said: (Aug 29, 2015)  
What is meant by Static function?


Thazaar said: (Sep 11, 2015)  
Friend function is used to access the private data member of a class. So it is not a member of a class.


Jeswanth Kumaar.C.S.G said: (Oct 3, 2015)  
Because we don't have friend function in C++. We have only friend function and friend class in C++.


Abhishek Chaudhary said: (Oct 14, 2015)  
If friend function will be the member function of the class then it can access private data member of the class without using friend function.


Mych5 said: (Oct 22, 2015)  
What is static function and where they are applicable?


Priyanka Patil said: (Feb 26, 2016)  
What is friend function?


Chetan said: (Aug 16, 2016)  
A friend is a function, i.e. It's not member of the class but has access to private and protected members of the class.


Ahmad said: (Sep 26, 2016)  
Without Virtual function can we dynamic binding?


Muhammad Abdul Khaliq said: (Jul 28, 2017)  
Static Function Can Be The Past of Class?


Nandita Pandey said: (Aug 10, 2018)  
Since friend functions are used by the methods that want to access the private data members of a class. They are only declared in the class and defined outside the class hence, they are not the members of a class.


Piyush said: (Sep 9, 2019)  
Yes, correct @Nandita. Thanks.


Swastik said: (Nov 23, 2019)  
You declare function as a friend inside class but it is not considered as member function of the class.


Arati said: (Mar 3, 2021)  
I think static is correct.


Goldy said: (Sep 3, 2021)  
Is it possible to modify a private data member of a class through a non-member function? If yes means How? Explain.


Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.




Which functions can only be called by another function that is a member of its class?

Explanation: We can call one function inside another function to access some data of class. A public member function can be used to call a private member function which directly manipulates the private data of class.

Which members of a class can be accessed by a member function?

A member function of a class is a function that has its definition or its prototype within the class definition like any other variable. It operates on any object of the class of which it is a member, and has access to all the members of a class for that object.

Can any member function of the class call to other member function of the same class?

There are two ways to call another method function from the same class. First, you can use a dot/period to access the method from the class variable. Second, you can simply call the function and pass the class object as an argument.

Which function is a member of class?

Member functions are operators and functions that are declared as members of a class. Member functions do not include operators and functions declared with the friend specifier. These are called friends of a class. You can declare a member function as static ; this is called a static member function.