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 is the significance of classes in oop?

0 Answers  


write a program using c++ to implement single contiguous memory mangement techniques.display the content of the main memory after yhe allocation of jobs and percentage of the wastage of the main memory

0 Answers  


which is best institute to learn c,c++ in ameerpet hyderabad

1 Answers  


What is inheritance in simple words?

0 Answers  


In the following declaration of main, "int main(int argc, char *argv[])", to what does argv[0] usually correspond? 1) The first argument passed into the program 2) The program name 3) You can't define main like that

6 Answers  


#include <stdio.h> #include <alloc.h> #include <stdlib.h> #include <conio.h> void insert(struct btreenode **, int); void inorder(struct btreenode *); struct btreenode { struct btreenode *leftchild; struct btreenode *rightchild; int data; }; main() { struct btreenode *bt; bt=(struct btreenode *)NULL; int req,i=1,num; clrscr(); printf("Enter number of nodes"); scanf("%d",&req); while(i<=req) { printf("Enter element"); scanf("%d",&num); insert(&bt,num); i++; } inorder(bt); } void insert(struct btreenode **sr, int num) { if(*sr==NULL) { *sr=(struct btreenode *)malloc (sizeof(struct btreenode)); (*sr)->leftchild=(struct btreenode *)NULL; (*sr)->rightchild=(struct btreenode *)NULL; (*sr)->data=num; return; } else { if(num < (*sr)->data) insert(&(*sr)->leftchild,num); else insert(&(*sr)->rightchild,num); } return; } void inorder(struct btreenode *sr) { if(sr!=(struct btreenode *)NULL) { inorder(sr->leftchild); printf("\n %d",sr->data); inorder(sr->rightchild); } else return; } please Modify the given program and add two methods for post order and pre order traversals.

0 Answers  


what are the realtime excercises in C++?

0 Answers   IBM, Wipro,


Program to print 0 to 9 in cross order

3 Answers  


What is function overloading and operator overloading?

4 Answers  


what is the difference b/w abstract and interface?

2 Answers   Merrill Lynch, Schneider, Scio Healthcare,


What is object in oop with example?

0 Answers  


What is abstrac class?where is it use?

2 Answers  


Categories