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 |
me get an assignent n its question is this 1.creat a set as in math i.ea={1,2} 2.insert element in it3. delete element don,t repeat any element 4.union 5. intersection of two sets plz help me i always pray for u n send me at ayeshawzd@hotmail.com f u have c++ how to program 5th addition then it is the 10.9 question in 10th chapter exercise
Finding of the 4 larger (bigger) numbers from the list like{1245,4587,2145,1163,29987,65783.....}
what is the difference between class and object?
What are the 4 pillars of oop?
The IT giant Tirnop has recently crossed a head count of 150000 and earnings of $7 billion. As one of the forerunners in the technology front, Tirnop continues to lead the way in products and services in India. At Tirnop, all programmers are equal in every respect. They receive identical salaries and also write code at the same rate. Suppose 14 such programmers take 14 minutes to write 14 lines of code in total. How long will in take 5 programmers to write 5 lines of code in total ?
inheritence with example
How to calculate the age from the date of birth by using the program?
Why do we use virtual functions?
What is Difeerence between List obj=new ArrayList(); and ArrayList obj=new ArrayList()?
What is the difference between a constructor and a destructor?
Get me a number puzzle game-program
Prepare me a program for the animation of train