Google Interview Question for Developer Program Engineers


Country: India
Interview Type: Written Test




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

Base::Display is non-virtual, which means that when you call it there isn't a v-table lookup, so it just calls based on the static type of the pointer (in this case Base).

- SirPentor December 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

homework crap

- Sirius April 27, 2014 | Flag
Comment hidden because of low score. Click to expand.
5
of 5 vote

This cannot a google interview question. This is basic rule of inheritance+ virtual function
if base class does not have virtual function ==-> function calling is based on type of pointer
and if the base class contain a virtual function then that function will be called on the base of content of the pointer.


So in this case the display is not virtual.. to the display of base class is called because you are accessing it via base class pointer.

try to run this code

#include <iostream>
using namespace std;

class Base {
public:
char* name;
virtual void display() {
cout << name << endl;
}
};

class Derived: public Base {
public:
char* name;
void display() {
cout << name << ", " << Base::name << endl;
}
};

int main() {
Derived d;
d.name = "Derived Class";
d.Base::name = "Base Class";

Derived* dptr = &d;

// standard conversion from Derived* to Base*
Base* bptr = dptr;

// call Base::display()
bptr->display();
}

in the code the display() drived class will be called as content of base pointer is a address of drived calls instance..that is the content of the pointer is a drived class.

- yogi.rulzz December 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 3 vote

Is this really Google's question?

- Rahul December 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

base class pointer doesnt have scope to point to derive class in any condition...

- nits December 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

make the display function as virtual in base class, then it works as expected..

virtual display();

- Anonymous December 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Who are all answering should understand that it is not quality of question that matters, it is quality of answer you give, I know about Amazon/Google interviews where they have asked program to find prime number. Every Google interviewer has his own bar while interviewing. Some usually like to start with simple program like reverse a string first check how the candidate can think and see if we can code.Then only tougher questions and stronger discussions could be made.
So, rather than commenting on how simple questions it kindly, recommended to provide quality answers.

- Anonymous December 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It is not about simplicity. It is about people using this site as domyhomework.com, and posting misleading the kind of questions they ask.

For instance, looking at this question one might assume Google is interested in specific programming language specifics (which is quite false) and trying to prepare for that can really deter from what you really need to prepare for: having a good grasp of the basics and being able to apply the basics, demonstrating problem solving skills.

- Anonymous December 24, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

this cant be a google interview question.. patilsanketv - you are lucky enough to answer this kind of question especially in Google interviews..

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

Although Base::display is not a virtual method, the Derived::display will explicitly output Base::name which contains "Base Class".

- cosmin January 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

come on man!!! If you dont come, someone else will come on.

- dhoni January 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

po raa

- jeelabi February 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

thanks for your ans :)

- shakela..... February 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i lov you shakela....

- jeelabi February 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

thanks for your ans jeelabi.....

- jangrie February 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i want to write answer??

- neel November 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It is hsowing the answer as Derived Class, Base Class

- Rock August 28, 2015 | 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