4) The idea behind inheritance is to allow one to inherit some and from a previo
ID: 3836739 • Letter: 4
Question
4) The idea behind inheritance is to allow one to inherit some and from a previously defined . In this way, the new can have a smaller definition while still containing all of the material of both itself and its ancestor.
A) type, actions, data, class, object
B) class, attributes, behaviors, type, class
C) variable, data, methods, class, object
D) function, static data, arguments, function, function E) function, arguments, references, library, program
5) TRUE / FALSE TRUE / FALSE
TRUE / FALSE TRUE / FALSE
In polymorphism, the keyword mutable is used.
Once a method (of a particular overload signature) is virtual, any derived classes which override it are
using polymorphism.
Of course, the derived classes must still use the virtual keyword for this to work. Any overloaded versions of such methods will also be polymorphic.
6) The idea behind polymorphism is to allow a pointer to point objects from any ’remember’ which actual it was pointing to and call the correct method.
A) base, derived, pointer, class, virtual
B) function, arguments, references, library, program
C) polymorphic, polymorphic, function, object, polymorphic D) class, attributes, behaviors, type, class
E) const, ractually blanks, object, argument, ractually blanks
class. In this way, the can
7) TRUE / FALSE Of all the methods to make virtual, the least important is the destructor.
TRUE / FALSE If the destructor isn’t virtual, the class objects won’t be completely destroyed and we will fragment our
heap.
8) Given the following inheritance hierarchy:
class One class Two : public One {{
public: public:
};
};
void print(void) const;
void print(void) const;
Tell what happens in the following code (specifically, which print() method is called in each case):
Why is this happening?
Explanation / Answer
4) The idea behind inheritance is to allow one to inherit some and from a previously defined . In this way, the new can have a smaller definition while still containing all of the material of both itself and its ancestor.
A) type, actions, data, class, object
B) class, attributes, behaviors, type, class
C) variable, data, methods, class, object
D) function, static data, arguments, function, function
E) function, arguments, references, library, program
Answer:
Question is correct but more appropriate options need to be provided.
5) TRUE / FALSE TRUE / FALSE
TRUE / FALSE TRUE / FALSE
In polymorphism, the keyword mutable is used.
Answer:- TRUE:
Explanation:
The function to be called is evaluated on the basis of the cv-qualifier(const/volatile) of the passed object. Note that cv-qualifiers are considered while function overload resolution.
If passed object is const, function receiving const argument is selected.If passed object is non-const then function receiving non-const argument is selected.
Once a method (of a particular overload signature) is virtual, any derived classes which override it are
using polymorphism.
Answer:- TRUE
Explanation:-As per design.
Of course, the derived classes must still use the virtual keyword for this to work.
Answer:- FALSE
Explanation: By default derived class base class virtual function is virtual. So use of virtual keyword is optional.
Any overloaded versions of such methods will also be polymorphic.
Answer:- TRUE
We can have virtual function having same name and different type of parameters type or different number of parameters.
6) The idea behind polymorphism is to allow a pointer to point objects from any ’remember’ which actual it was pointing to and call the correct method.
A) base, derived, pointer, class, virtual
B) function, arguments, references, library, program
C) polymorphic, polymorphic, function, object, polymorphic D) class, attributes, behaviors, type, class
E) const, ractually blanks, object, argument, ractually blanks
class. In this way, the can
7) TRUE / FALSE Of all the methods to make virtual, the least important is the destructor.
TRUE / FALSE If the destructor isn’t virtual, the class objects won’t be completely destroyed and we will fragment our
heap.
TRUE:
Explanation:
#include <iostream>
using namespace std;
class base
{
public:
base(){cout<<"Base Constructor Called ";}
~base(){cout<<"Base Destructor called ";}
};
class derived1:public base
{
public:
derived1(){cout<<"Derived constructor called ";}
~derived1(){cout<<"Derived destructor called ";}
};
int main()
{
base* b;
b=new derived1;
delete b;
}
Output:
Base Constructor Called
Derived constructor called
Base Destructor called
Now let see what happen if destructor is virtual
#include <iostream>
using namespace std;
class base
{
public:
base(){cout<<"Base Constructor Called ";}
virtual ~base(){cout<<"Base Destructor called ";}
};
class derived1:public base
{
public:
derived1(){cout<<"Derived constructor called ";}
~derived1(){cout<<"Derived destructor called ";}
};
int main()
{
base* b;
b=new derived1;
delete b;
}
Output:
Base Constructor Called
Derived constructor called
Derived destructor called
Base Destructor called
So making destructor virtual destroyes objects completely.
8) Given the following inheritance hierarchy:
class One class Two : public One {{
public: public:
};
};
void print(void) const;
void print(void) const;
Tell what happens in the following code (specifically, which print() method is called in each case):
One o;
Two t;
One * p;
p = &o;
p->print();
p = &t;
p->print();
Why is this happening?
Answer:-
Please provide actual code snippet of both class and print method.
I am answering, with consideration that print method exists in both class One and class two.
To allow polymorphism You just have to make sure that the methods have the same signature (including const/mutable modifiers and argument types). To get print method overrided you should declare it as virtual. Then your problem will get solved and appropriate print method will get called.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.