UpTest > General Programming > C++ Programming Test

Test: C++ Programming Test

Question 1: Prev Next Hide answers

Consider the sample code given below and answer the question that follows.

class Shape
{
public:
virtual void draw() = 0;
};

class Rectangle: public Shape
{
public:
void draw()
{
// Code to draw rectangle
}
//Some more member functions.....
};

class Circle : public Shape
{
public:
void draw()
{
// Code to draw circle
}
//Some more member functions.....
};

int main()
{
Shape objShape;
objShape.draw();
}

What happens if the above program is compiled and executed?

Object objShape of Shape class will be created
0 votes
A compile time  error will be generated because you cannot declare Shape objects
1 votes
A compile time error will be generated because you cannot call draw function of class 'Shape'
0 votes
A compile time error will be generated because the derived class's draw() function cannot override the base class draw() function
0 votes
None of the above
0 votes
Please login to submit your answer.