Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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 causes polymorphism?

0 Answers  


what are the ways in which a constructors can be called?

2 Answers   TCS,


What is Hashing and how is it done? Pictorial form?

2 Answers   emc2, Wipro,


What's the full form of STL?

2 Answers  


what is object slicing

3 Answers   TCS,


What is a macro? And how is a macro same as a template?

4 Answers  


Is following functions are said to be overloaded? int add(int a,int b) char *add(int a,int b)

4 Answers  


What is the Advantage of Interface over the Inheritance in OOPS?

4 Answers  


Can anyone please explain runtime polymorphism with a real time example??at what ciscumstances we go for it??

1 Answers  


Should you protect the global data in threads? Why or why not?

2 Answers   IBM,


char* ptr = "Rahul"; *ptr++; printf("%s",ptr); What will be the output

9 Answers   Persistent,


Is react oop?

0 Answers  


Categories