Yahoo Interview Question for Software Engineer / Developers






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

Was this question asked in Yahoo ? At which level ?

- Time pass ! February 19, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1) for basic data type for example say... Sum(a,b) or Sum(1,2) , this is call by value , as even if the data passed to method is altered value of a , b doesn't change their values.

2) Passing array of int ( i.e primitive data type ) also belongs to call by value.

3) Whenever we pass the instance of non-primitive data type then it is pass by reference. and Hence if the value of the object gets modified in called method it would reflect in caller too.

- MasterSolution June 20, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry second is wrong....arrays are treated as object in java. Hence it nothing but another object. so pass by reference( not really, we say it "reference is passed by value")

- master January 01, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Sorry for above comments....some correction...

When we pass variables , the copy of the variable is made in target method. Hence we will not see any change to original variables.

When we pass object... first of all we are not passing the object, we always pass reference of the object, and the reference is passed by value . What it means is There will two reference created for same object. One in target method and other is source.

Hence if you assign anything directly to target method references then source reference will continue to point to original object. But if you change change any member variable using target reference, source reference object values will also change, as both the reference are pointing to the same object.

- Mater Solution June 20, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

2) Passing array of int ( i.e primitive data type ) also belongs to call by value.
is wrong:

int [] a = new int [2];
a[0] = 0;
a[1] = 1;
testArray(a);
System.out.println(a[0]);


public static void testArray(int []a) {
a[0] = 1;
}

the result is 1

- le September 16, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

2) Passing array of int ( i.e primitive data type ) also belongs to call by value.
is wrong:

int [] a = new int [2];
	   a[0] = 0;
	   a[1] = 1;
	   testArray(a);
	   System.out.println(a[0]);
	   
	
	public static void testArray(int []a) {
		a[0] = 1;
	}

the result is 1

- le September 16, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

array of int is pass-by-value-of-reference.... google it out.

Now the details...

The problem we're facing here is statements like

In Java, Objects are passed by reference, and primitives are passed by value.

This is half incorrect. Everyone can easily agree that primitives are passed by value; there's no such thing in Java as a pointer/reference to a primitive.

However, Objects are not passed by reference. A correct statement would be Object references are passed by value.

This may seem like splitting hairs, bit it is far from it. There is a world of difference in meaning. The following examples should help make the distinction.

refer : httx://javadude.com/articles/passbyvalue.htm

- le Corrected November 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

array of int is pass-by-value-of-reference.... google it out.

Now the details...

The problem we're facing here is statements like

In Java, Objects are passed by reference, and primitives are passed by value.

This is half incorrect. Everyone can easily agree that primitives are passed by value; there's no such thing in Java as a pointer/reference to a primitive.

However, Objects are not passed by reference. A correct statement would be Object references are passed by value.

This may seem like splitting hairs, bit it is far from it. There is a world of difference in meaning. The following examples should help make the distinction.

refer : javadude.com/articles/passbyvalue.htm

- le Corrected November 27, 2009 | 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