Question:Consider the following code:
class Animal
{
private:
    int weight;

public:
    Animal()
    {
    }

    virtual void Speak()
    {
        cout << "Animal speaking";
    }
};

class Snake : public Animal
{
private:
    int length;

public:
    Snake()
    {
    }

    void Speak()
    {
        cout << "Snake speakingrn";
    }
};

int main()
{
    Animal *array = new Snake[10];

    for (int index= 0; index < 10; index++)
    {
        array->Speak();
        array++;
    }
    
    return 0;
}
What happens when the above code is compiled and executed? 

A The code will generate compilation errors 

B The code will compile and run fine. "Animal speaking" will be printed to the output 

C The code will compile and run fine. "Snake speaking" will be printed to the output 

D The code will crash at runtime 

+ Answer
+ Report
Total Preview: 1534

Copyright © 2024. Powered by Intellect Software Ltd