Ebay Interview Question for Software Engineer / Developers






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

by adding getters in the base class and calling it from the derived class object.

- Anonymous September 16, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

#define private public
... access whatever you want
#undefine private

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

The answer to this question could be found at herb sutter 's - exceptional c++.

- HёLL August 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

well done surath... phod diya yaar:):):):) anna..

- Anonymous September 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

well done surath... phod diya yaar:):):):) anna...

- Anonymous September 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A hack could be done by knowing the object layout.
All we need to do is find the address of derived object and subtract necessary offset and get hold of that memory location.
After that cast the pointer to the data type to which we want to access

- Amit Priyadarshi September 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hi, pvs, temp is not derived from base?

- Anonymous November 07, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am not sure about hacking but seems private data of base class wouldn't be accessible in main(). Only member functions of that class would be able to access private data.

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

Reflections!!!

- Sam February 09, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Reflections?!
Why not make a space ship?

Why isn't this good enough bozos?
"by adding getters in the base class and calling it from the derived class object."

- alphatheta February 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

thanks - public getters and setters work to access private members of base class from a derived class.

- andy March 04, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Simple! Make a public function in base class that can access the private data members. All public methods can be accessed through the derived class.

- MM March 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#include<iostream>

using namespace std;

class base
{
private:int i;
public:base(int k)
{
i=k;
}
};

class temp
{
public: int i;
};

int main()
{
base b(10);
//temp p;
//p = (temp)b;
cout<< (reinterpret_cast<temp*>(&b))->i<<endl;
}

- pvs October 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

No, it will not work.
Actually, it will not work even if we say:

cout<< b.i <<endl;

We should be inside the class to access it's private members!

- sergey.a.kabanov January 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#include<iostream>

using namespace std;

class base
{
private:int i;
public:base(int k)
{
i=k;
}
};

class temp
{
public: int i;
};

int main()
{
base b(10);
//temp p;
//p = (temp)b;
cout<< (reinterpret_cast<temp*>(&b))->i<<endl;
}

- pvs October 21, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

#include<iostream>

using namespace std;

class base
{
private:int i;
public:base(int k)
{
i=k;
}
};

class temp
{
public: int i;
};

int main()
{
base b(10);
cout<< (reinterpret_cast<temp*>(&b))->i<<endl;
}

- pvs October 21, 2010 | 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