Child cObj = new Parent()
Wahts the output ?
Answers were Sorted based on User's Feedback
Answer / bhavin pandya
It will give yo Error :-
Object reference not set to an instance of an object.
If you want to create object then
Child cObj = new Child()
this is the right way
| Is This Answer Correct ? | 8 Yes | 3 No |
Answer / austin j seelan
Child cObj = new Parent()
This will through the compiletime error.
but we can create an instance like the foll.way
parent objparent = new child()
| Is This Answer Correct ? | 7 Yes | 2 No |
Answer / bangarraju
This is the DownCasting,but using like this
Child* obj=down_cast<Child* >(Parent) either using RTTI
mechanism in C++
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / donga bangarraju
sorry for the earlier post, this output is giving error like
initializing cannot convert to Paretn* to Child*, if u want
correct this code write like this, this is downcasting or
using RTTI mechanism in C++;
Parent* p =new Child;
Child* obj= dynamic_cast<Child*>(p);
| Is This Answer Correct ? | 1 Yes | 1 No |
Answer / aditya
Its java syntax where there is no pointers.
So its dynamic method dispatch which is same as virtual
functions of c++.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / chetan
it will execute without an error. if Parent class is
parent/base class and child is the child/drive class which
inherit parent class.
In the other worlds you are invoking drive class method with
the reference of base class.
| Is This Answer Correct ? | 3 Yes | 3 No |
Answer / giri
You can write below ways [Upcasting].
Child *cObj = new Parent();
| Is This Answer Correct ? | 5 Yes | 10 No |
all about pointers
What is polymorphism in oop example?
What is debug class?what is trace class? What differences are between them? With examples.
When a private constructer is being inherited from one class to another class and when the object is instantiated is the space reserved for this private variable in the memory??
Why many objects can working together? How objects working togetherM I want to see example code.
What is R T T I ?
What is polymorphism what is it for and how is it used?
i am getting an of the type can not convert int to int *. to overcome this problem what we should do?
Why is there no multiple inheritance?
What is the difference between procedural programming and oops?
What is oops and its features?
What do you mean by binding of data and functions?