Exercise: Objects And Classes
Questions for: Objects And Classes
What will be the output of the following program?
#include<iostream.h>
class BixTeam
{
int x, y;
public:
BixTeam(int xx)
{
x = ++xx;
}
void Display()
{
cout<< --x << " ";
}
};
int main()
{
BixTeam objBT(45);
objBT.Display();
int *p = (int*)&objBT;
*p = 23;
objBT.Display();
return 0;
}
A:
45 22
B:
46 22
C:
45 23
D:
46 23
Answer: A
No answer description is available. Let's discuss.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class ExamAdept
{
static int x;
public:
static void SetData(int xx)
{
x = xx;
}
static void Display()
{
cout<< x ;
}
};
int ExamAdept::x = 0;
int main()
{
ExamAdept::SetData(44);
ExamAdept::Display();
return 0;
}
A:
The program will print the output 0.
B:
The program will print the output 44.
C:
The program will print the output Garbage.
D:
The program will report compile time error.
Answer: B
No answer description is available. Let's discuss.
Discuss About this Question.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class ExamAdept
{
static int x;
public:
static void SetData(int xx)
{
x = xx;
}
void Display()
{
cout<< x ;
}
};
int ExamAdept::x = 0;
int main()
{
ExamAdept::SetData(33);
ExamAdept::Display();
return 0;
}
A:
The program will print the output 0.
B:
The program will print the output 33.
C:
The program will print the output Garbage.
D:
The program will report compile time error.
Answer: D
No answer description is available. Let's discuss.
Discuss About this Question.
What will be the output of the following program?
#include<iostream.h>
class Bix
{
public:
int x;
};
int main()
{
Bix *p = new Bix();
(*p).x = 10;
cout<< (*p).x << " " << p->x << " " ;
p->x = 20;
cout<< (*p).x << " " << p->x ;
return 0;
}
A:
10 10 20 20
B:
Garbage garbage 20 20
C:
10 10 Garbage garbage
D:
Garbage garbage Garbage garbage
Answer: A
No answer description is available. Let's discuss.
Discuss About this Question.
Which of the following statements are correct for a static member function?
- It can access only other static members of its class.
- It can be called using the class name, instead of objects.
A:
Only 1 is correct.
B:
Only 2 is correct.
C:
Both 1 and 2 are correct.
D:
Both 1 and 2 are incorrect.
Answer: C
No answer description is available. Let's discuss.
Discuss About this Question.
Ad Slot (Above Pagination)
Discuss About this Question.