PayPal Interview Question for Software Engineer / Developers






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

inheritance always inherits all the bits and services of base class(sizeof confirms this!).. the only difference is access levels.private inheritance doesnot mean that privete members are not inherited.. they are.. but there access isnt given to the derived objects..so the ambiguity problem remains intact weather one of the middle class is privately or publicly derived.So this does not solve the diamond inheritance problem.

- ashish August 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

no it does not....because the middle class inherits privately all members of the base class...but the last class which inherits the middle class can also access the private methods and data of middle class...thus the last class again ends up with two copeis of 1st base class....hence problem not solved...only way to solve it is by using virtual base class

- Anonymous May 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

private members are never inherited . if privately inherited the middle will contain private elemnts inherited from it's parent. so the last class cant access any private member of middle class

- kamlesh June 14, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

If we derive one of the middle base class as private then the last base class cant inherit any of its methods. Then the last class will lose some methods. If we derive middle base class all members as public then there is duplicate when last class inherits them. So when we use keyword virtually, then the languages itself handles and gives only one copy. So the problem is solved.

- Sati June 30, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You are right Sati

- Birbal August 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

It is possible.

- Badri July 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Without virtual keyword, the derived class will still have two copies of first base class (parent of middle classes) leading to ambiguity. So private inheritance doesn't solve ambiguity.

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

Yes, it still need to use virtual. In fact if you use private while inheriting the class, it will give compile time error as you are accessing private member function instead to follow other class path.

So, the private option is not possible at all.

- manish2you September 24, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<iostream.h>

class a
{
int var;
public:

a()
{
var=10;
}
 void fn()
{
cout<<var<<endl;
}
};
class b: private a
{
};
class c:public a
{
};
class d:private b, public c 
{
};
int main()
{
d d1;

d1.fn();
}

In this still ambiguous error is thrown. Which is solved only when we declare inheritance as virtual.
coz var is still inherited by class b (only class b object cant access them) and class c.
Hence ambiguity arises

- devanshi choudhary April 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

ArrayList is the fastest solution. You can use HashSet too, however AL is a bit faster.

public static void main(String[] args) {
		int[] arr = { 1, 3, 67, 3, 6, 88, 9, 56, 4, 5, 7, 23, 4, 99 };
		removeDuplicatesUsingAL(arr);
//		removeDuplicatesUsingHashSet(arr);
	}

	public static void removeDuplicatesUsingAL(int[] arr) {
		long startTime = System.nanoTime();
		System.out.println("Start time: " + startTime);
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < arr.length; i++) {
			if (!list.contains(arr[i])) {
				list.add(arr[i]);
			}
		}

		for (Integer i : list) {
			System.out.println("values are: " + i);
		}
		long endTime = System.nanoTime();
		System.out.println("End time: " + endTime);
		System.out.println("total Time is: " + (endTime - startTime));
	}

	public static void removeDuplicatesUsingHashSet(int[] arr) {
		long startTime = System.nanoTime();
		System.out.println("Start time: " + startTime);
		Set hashSet = new HashSet();
		for (int i = 0; i < arr.length; i++) {
			if (!hashSet.contains(arr[i])) {
				hashSet.add(arr[i]);
			}
		}

		Iterator iter = hashSet.iterator();
		while (iter.hasNext()) {
			System.out.println("values are: " + iter.next());
		}
		long endTime = System.nanoTime();
		System.out.println("End time: " + endTime);
		System.out.println("total Time is: " + (endTime - startTime));
	}

Below is a sample run:-
The time taken for AL: 1876787
The time taken for HS: 1756755

- Hariharan Vedamurthy August 24, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The above code is a mistake. It was meant for another post. posted wrongly.

- Hariharan Vedamurthy August 24, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

we cant use the class which declared as private constructor through instance. So it will be used for adding only class specific static members. If it is used in inheritance , then implicit super constructor loading itself will fail. or if we say public middle class with private members, still we are not achieving multiple inheritance. private members considered only for the middle parent class. So no relationship and sharing.

- Francis M October 24, 2017 | 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