C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 20)
20.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiabixSample
{
private:
int AdditionOne(int x, int y = 1)
{
return x * y;
}
public:
int AdditionTwo(int x, int y = 1)
{
return x / y;
}
};
int main()
{
IndiabixSample objBix;
cout<<objBix.AdditionOne(4, 8)<<" ";
cout<<objBix.AdditionTwo(8, 8);
return 0;
}
Discussion:
5 comments Page 1 of 1.
Uma said:
1 decade ago
Because Private members can't be accessed in main function.
Abhijit Indore said:
1 decade ago
Private members can't be accessed in main function.
private:
int AdditionOne(int x, int y = 1)
{
return x * y;
}
private:
int AdditionOne(int x, int y = 1)
{
return x * y;
}
Ravi said:
1 decade ago
Because private members can't be directly accessed by class object.
Sachin said:
8 years ago
Sir, how to make it accessible in main ()?
John said:
7 years ago
Sachin: make it public or use a friend class
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers