C++ Programming - Objects and Classes
Exercise : Objects and Classes - Programs
- Objects and Classes - General Questions
- Objects and Classes - Programs
11.
What will be the output of the following program?
#include<iostream.h>
class IndiaBix
{
static int count;
public:
static void First(void)
{
count = 10;
}
static void Second(int x)
{
count = count + x;
}
static void Display(void)
{
cout<< count << endl;
}
};
int IndiaBix::count = 0;
int main()
{
IndiaBix :: First();
IndiaBix :: Second(5);
IndiaBix :: Display();
return 0;
}
12.
What will be the output of the following program?
#include<iostream.h>
class BixBase
{
public:
float x;
};
class BixDerived : public BixBase
{
public:
char ch;
void Process()
{
ch = (int)((x=12.0)/3.0);
}
void Display()
{
cout<< (int)ch;
}
};
int main()
{
class BixDerived *objDev = new BixDerived;
objDev->Process();
objDev->Display();
return 0;
}
13.
Which of the following statement is correct about the program given below?
#include<iostream.h>
#include<process.h>
class IndiaBix
{
static int x;
public:
IndiaBix()
{
if(x == 1)
exit(0);
else
x++;
}
void Display()
{
cout<< x << " ";
}
};
int IndiaBix::x = 0;
int main()
{
IndiaBix objBix1;
objBix1.Display();
IndiaBix objBix2;
objBix2.Display();
return 0;
}
14.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class BixBase
{
int x, y;
public:
BixBase(int xx = 10, int yy = 10)
{
x = xx;
y = yy;
}
void Show()
{
cout<< x * y << endl;
}
};
class BixDerived
{
private:
BixBase objBase;
public:
BixDerived(int xx, int yy) : objBase(xx, yy)
{
objBase.Show();
}
};
int main()
{
BixDerived objDev(10, 20);
return 0;
}
15.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class BixBase
{
int x, y;
public:
BixBase(int xx = 10, int yy = 10)
{
x = xx;
y = yy;
}
void Show()
{
cout<< x * y << endl;
}
};
class BixDerived : public BixBase
{
private:
BixBase objBase;
public:
BixDerived(int xx, int yy) : BixBase(xx, yy)
{
objBase.Show();
}
};
int main()
{
BixDerived objDev(10, 20);
return 0;
}
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers