Question
1.
#include
2.
using namespace std;
3.
class number
4.
{
5.
int i;
6.
public:
7.
int geti();
8.
void puti(int j);
9.
};
10.
int number::geti()
11.
{
12.
return i;
13.
}
14.
void number::puti(int j)
15.
{
16.
i = j;
17.
}
18.
int main()
19.
{
20.
number s;
21.
s.puti(10);
22.
cout
What is the output of this program?
1.
#include
2.
using namespace std;
3.
class number
4.
{
5.
int i;
6.
public:
7.
int geti();
8.
void puti(int j);
9.
};
10.
int number::geti()
11.
{
12.
return i;
13.
}
14.
void number::puti(int j)
15.
{
16.
i = j;
17.
}
18.
int main()
19.
{
20.
number s;
21.
s.puti(10);
22.
cout
Answer: Option A
Was this answer helpful ?
We are getting the number and copying it to j and printing it.
Output:
$ g++ obj2.cpp
$ a.out
10
Was this answer helpful ?
More Questions on This Topic :
Question 3.
Pick out the other definition of objects.
....
Question 8.
How to access the object in the class?
....
Question 9.
Where does the object is created?
....
Submit Solution