169k views
1 vote
Suppose that we have a Question class that contains two data members - a query and answer both of which are type string. The NumericQuestion class is derived from Question. Which of the following is true?

a. NumericQuestion contains a numerical answer but not a query
b. NumericQuestion contains a query and a numerical answer but no answer string
c. It is impossible to know without examining the definition of the NumericQuestion class
d. NumericQuestions contains both a query and an answer string.

2 Answers

4 votes

Final answer:

The NumericQuestion class contains both a query and an answer string.

Step-by-step explanation:

The correct option is d. NumericQuestions contains both a query and an answer string.

The question states that the Question class contains a query and an answer string, and the NumericQuestion class is derived from Question. This means that the NumericQuestion class inherits the properties of the Question class, including the query and answer string.

Therefore, NumericQuestion contains both a query and an answer string.

User Peetman
by
7.5k points
4 votes

Option (d) is the correct statement.

Based on the information provided, we have a `Question` class that contains two data members: a query and an answer, both of which are of type string. Additionally, we have a `NumericQuestion` class derived from `Question`. To determine which statement is true, let's analyze the inheritance and what we know about the classes:

1. `Question` class:

- Contains two data members: a query (string) and an answer (string).

2. `NumericQuestion` class (derived from `Question`):

- Inherits the data members from the `Question` class.

Now, let's analyze the given options:

a. "NumericQuestion contains a numerical answer but not a query."

- This statement is not true because we know that the `Question` class contains both a query and an answer, and the `NumericQuestion` class inherits these members. So, `NumericQuestion` contains both a query and an answer.

b. "NumericQuestion contains a query and a numerical answer but no answer string."

- This statement is also not true. We know that the `Question` class contains both a query and an answer (both of type string), and the `NumericQuestion` class inherits these members. So, `NumericQuestion` contains both a query and a string answer.

c. "It is impossible to know without examining the definition of the NumericQuestion class."

- This statement is not true either. We can make a reasonable conclusion based on the information provided.

d. "NumericQuestions contains both a query and an answer string."

- This statement is true. The `NumericQuestion` class, which is derived from the `Question` class, inherits both the query and the answer (both are of type string). So, `NumericQuestion` contains both a query and an answer string.

User EagleBeak
by
8.1k points

No related questions found