Bank of America Interview Question


Country: India




Comment hidden because of low score. Click to expand.
1
of 1 vote

Can we use downCasting here ? . Converting a base-class pointer (reference) to a derived-class pointer (reference) is called downcasting. Downcasting is not allowed without an explicit type cast.The downcasting in the above line can lead to an unsafe operation.C++ provides a special explicit cast called dynamic_cast that performs this conversion
Base * b = new Base();
derived * d = dynamic_cast<derived * >(b);

- Rohit Hajare March 28, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Base class pointer can pointer to the derived the class (in the case of public inheritance) and not the other way around. The derived classes might have moe data members and functions that the base class might not have and it is just no the right thing to do.

- Anonymous March 23, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@ ketan :
this is relevant to c++
Base is the parent class and Derived is the child class ..

- jkl March 23, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

C++ supports up-casting i.e. assigning the derived class object's address to base class pointer. The opposite of that , i.e. down-casting is not possible. Because the size of derived class object is always greater than or equal to that of base class, and so if any pointer arithmetic would cause unexpected results.

- sreehari.mysore March 24, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

The reason for this restriction is that the is-a relationship is not, in most of the cases, symmetric. A derived class could add new data members, and the class member functions that used these data members wouldn't apply to the base class. so if base class doesn't know anything about child class then how he behave like child class.

- Rohit Hajare March 28, 2016 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More