Child cObj = new Parent()
Wahts the output ?

Answers were Sorted based on User's Feedback



Child cObj = new Parent() Wahts the output ?..

Answer / deepthi

An error. We cant create such kinda objects.

Is This Answer Correct ?    20 Yes 5 No

Child cObj = new Parent() Wahts the output ?..

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

Child cObj = new Parent() Wahts the output ?..

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

Child cObj = new Parent() Wahts the output ?..

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

Child cObj = new Parent() Wahts the output ?..

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

Child cObj = new Parent() Wahts the output ?..

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

Child cObj = new Parent() Wahts the output ?..

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

Child cObj = new Parent() Wahts the output ?..

Answer / giri

You can write below ways [Upcasting].

Child *cObj = new Parent();

Is This Answer Correct ?    5 Yes 10 No

Post New Answer

More OOPS Interview Questions

What is multiple inheritance ?

17 Answers   Blue Star, C DAC, CDAC, Impetus, Ness Technologies, Softvision Solution,


What are the 3 pillars of oop?

0 Answers  


Is react oop?

0 Answers  


What is a function in oop?

0 Answers  


how many types of notations are in java

1 Answers   National University of Modern Languages (NUML),






INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?

0 Answers  


DIFFRENCE BETWEEN STRUCTURED PROGRAMING AND OBJCET ORIENTED PROGRAMING.

5 Answers  


What is Object and Class? What are the differences between them?

5 Answers  


what is difference between String s=new String("vali"); String s="vali"

1 Answers  


What is polymorphism what is it for and how is it used?

0 Answers  


what is the advantage in software? what is the difference between the software developer and Engineer

1 Answers  


What is polymorphism? Explain with an example.

48 Answers  


Categories