Answer Posted / p govind rao
if an object of a derived class is assigned to a base class
object,the compiler accepts it.but it copies only the base
portion of the object
#include<iostream>
using namespace std;
class base
{
public:
int i,j;
base(){i=2;j=3;}
virtual void show(){cout<<"i = "<<i<<endl<<"j = "<<j<<endl;}
};
class derived :public base
{
public :
int k;
derived(){k=4;}
void show() {
base::show();
cout<<"k = "<<k<<endl;
}
};
int main()
{
base b;
derived d;
d.show();
b=d;
b.show();
return 0;
}
OutPut is
i = 2
j = 3
k = 4
---------------
i = 2
j = 3
here b contains i and j where as d contains i,j&k.On
assignment only i and j of the d get copied into i and j of
b. k doesnot be copied. on the effect object d got sliced.
| Is This Answer Correct ? | 12 Yes | 1 No |
Post New Answer View All Answers
Why is oop better than procedural?
Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?
What is difference between pop and oop?
Write a java applet that computes and displays the squares of values between 25 and 1 inclusive and displays them in a TextArea box
Write A Program to find the ambiguities in Multiple Inheritance? How are they resolved.(Virtual Functions)
given a set based questions and 5 questions based on it next data sufficiciency questions 2 and 2/3 english sentence completion with options very easy and 2 synononmys paragraph with 10 questions 10 minutes replace =,-,*,% with -,%,+,* type questions 5 3 questions lik following itssickhere itssickthere itssickhere istsickhere which is nt alike the others very easy
What are the three parts of a simple empty class?
What do you mean by overloading?
Hi friends I have experience of 6 months in website design and maintanence. Now i am looking for other IT jobs.. to switch platform. please post any interview you know in chennai.
How do you use inheritance in unity?
Which language is pure oop?
How is polymorphism achieved?
What is encapsulation with real life example?
#include
Can an interface inherit a class?