Software Development Exam  >  Software Development Questions  >  Which statement is true about pure virtual fu... Start Learning for Free
Which statement is true about pure virtual functions in C++?
  • a)
    A pure virtual function has a definition in the base class
  • b)
    A class containing a pure virtual function cannot be instantiated
  • c)
    A pure virtual function cannot have any parameters
  • d)
    A pure virtual function can be overridden with a non-pure virtual function in a derived class
Correct answer is option 'B'. Can you explain this answer?
Most Upvoted Answer
Which statement is true about pure virtual functions in C++?a)A pure v...
A class containing a pure virtual function is called an abstract class. An abstract class cannot be instantiated, meaning objects of the abstract class cannot be created. However, a derived class can inherit from the abstract class and provide implementations for the pure virtual functions.
Free Test
Community Answer
Which statement is true about pure virtual functions in C++?a)A pure v...
Explanation:

A pure virtual function is a function in a base class that has no implementation and is meant to be overridden by derived classes. It is declared using the syntax `virtual returnType functionName(parameters) = 0;`.

Statement: A class containing a pure virtual function cannot be instantiated.

Explanation:
This statement is true. A class that contains a pure virtual function is called an abstract class. An abstract class cannot be instantiated, which means that objects of the abstract class cannot be created. The reason behind this is that the pure virtual function does not have an implementation in the base class, so it cannot be called.

When a class contains a pure virtual function, it becomes an abstract class. The purpose of an abstract class is to provide a common interface for all its derived classes. Each derived class must implement the pure virtual function, providing its own implementation. By making the base class abstract, we ensure that the derived classes must override the pure virtual function.

An example of an abstract class in C++:

```
class Shape {
public:
virtual void draw() = 0; // pure virtual function
};

class Circle : public Shape {
public:
void draw() {
// implementation of draw for Circle
}
};

class Rectangle : public Shape {
public:
void draw() {
// implementation of draw for Rectangle
}
};
```

In this example, the `Shape` class is an abstract class because it contains a pure virtual function `draw()`. The `Circle` and `Rectangle` classes are derived from `Shape` and provide their own implementation of the `draw()` function.

Attempting to create an object of the `Shape` class directly will result in a compilation error because the `Shape` class is abstract and cannot be instantiated:

```
Shape shape; // Error: cannot instantiate abstract class
```

Instead, we can create objects of the derived classes:

```
Circle circle;
Rectangle rectangle;
```

In conclusion, a class containing a pure virtual function cannot be instantiated, making the statement true.
Attention Software Development Students!
To make sure you are not studying endlessly, EduRev has designed Software Development study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Software Development.
Explore Courses for Software Development exam

Top Courses for Software Development

Which statement is true about pure virtual functions in C++?a)A pure virtual function has a definition in the base classb)A class containing a pure virtual function cannot be instantiatedc)A pure virtual function cannot have any parametersd)A pure virtual function can be overridden with a non-pure virtual function in a derived classCorrect answer is option 'B'. Can you explain this answer?
Question Description
Which statement is true about pure virtual functions in C++?a)A pure virtual function has a definition in the base classb)A class containing a pure virtual function cannot be instantiatedc)A pure virtual function cannot have any parametersd)A pure virtual function can be overridden with a non-pure virtual function in a derived classCorrect answer is option 'B'. Can you explain this answer? for Software Development 2024 is part of Software Development preparation. The Question and answers have been prepared according to the Software Development exam syllabus. Information about Which statement is true about pure virtual functions in C++?a)A pure virtual function has a definition in the base classb)A class containing a pure virtual function cannot be instantiatedc)A pure virtual function cannot have any parametersd)A pure virtual function can be overridden with a non-pure virtual function in a derived classCorrect answer is option 'B'. Can you explain this answer? covers all topics & solutions for Software Development 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Which statement is true about pure virtual functions in C++?a)A pure virtual function has a definition in the base classb)A class containing a pure virtual function cannot be instantiatedc)A pure virtual function cannot have any parametersd)A pure virtual function can be overridden with a non-pure virtual function in a derived classCorrect answer is option 'B'. Can you explain this answer?.
Solutions for Which statement is true about pure virtual functions in C++?a)A pure virtual function has a definition in the base classb)A class containing a pure virtual function cannot be instantiatedc)A pure virtual function cannot have any parametersd)A pure virtual function can be overridden with a non-pure virtual function in a derived classCorrect answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for Software Development. Download more important topics, notes, lectures and mock test series for Software Development Exam by signing up for free.
Here you can find the meaning of Which statement is true about pure virtual functions in C++?a)A pure virtual function has a definition in the base classb)A class containing a pure virtual function cannot be instantiatedc)A pure virtual function cannot have any parametersd)A pure virtual function can be overridden with a non-pure virtual function in a derived classCorrect answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Which statement is true about pure virtual functions in C++?a)A pure virtual function has a definition in the base classb)A class containing a pure virtual function cannot be instantiatedc)A pure virtual function cannot have any parametersd)A pure virtual function can be overridden with a non-pure virtual function in a derived classCorrect answer is option 'B'. Can you explain this answer?, a detailed solution for Which statement is true about pure virtual functions in C++?a)A pure virtual function has a definition in the base classb)A class containing a pure virtual function cannot be instantiatedc)A pure virtual function cannot have any parametersd)A pure virtual function can be overridden with a non-pure virtual function in a derived classCorrect answer is option 'B'. Can you explain this answer? has been provided alongside types of Which statement is true about pure virtual functions in C++?a)A pure virtual function has a definition in the base classb)A class containing a pure virtual function cannot be instantiatedc)A pure virtual function cannot have any parametersd)A pure virtual function can be overridden with a non-pure virtual function in a derived classCorrect answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Which statement is true about pure virtual functions in C++?a)A pure virtual function has a definition in the base classb)A class containing a pure virtual function cannot be instantiatedc)A pure virtual function cannot have any parametersd)A pure virtual function can be overridden with a non-pure virtual function in a derived classCorrect answer is option 'B'. Can you explain this answer? tests, examples and also practice Software Development tests.
Explore Courses for Software Development exam

Top Courses for Software Development

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev