Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
Does Java pass by Value or reference?
Does Java pass by Value or reference?
✍: Guest
Its uses Reference while manipulating objects but pass by value when sending method arguments. Those who feel why I added this simple question in this section while claiming to be maintaining only strong and interesting questions, go ahead and answer following questions.
a)What is the out put of:
import java.util.*;
class TestCallByRefWithObject
{
ArrayList list = new ArrayList(5);
public void remove(int index){
list.remove(index);
}
public void add(Object obj){
list.add(obj);
}
public void display(){
System.out.println(list);
}
public static void main(String[] args)
{
TestCallByRefWithObject test = new TestCallByRefWithObject();
test.add("1");
test.add("2");
test.add("3");
test.add("4");
test.add("5");
test.remove(4);
test.display();
}
}
b) And now what is the output of:
import java.util.*;
class TestCallByRefWithInt
{
int i = 5;
public void decrement(int i){
i--;
}
public void increment(int i){
i++;
}
public void display(){
System.out.println("\nValue of i is : " +i);
}
public static void main(String[] args)
{
TestCallByRefWithInt test = new TestCallByRefWithInt();
test.increment(test.i);
test.display();
}
}
2013-03-20, 2291👍, 0💬
Popular Posts:
How do I use a scriptlet to initialize a newly instantiated bean? A jsp:useBean action may optionall...
How was XML handled during COM times? During COM it was done by using MSXML 4.0. So old languages li...
Can you explain project life cycle ? Figure :- 12.2 Life cycle of a project There are five stages of...
Can one change the mouse pointer in Forms? The SET_APPLICATION_PROPERTY build-in in Oracle Forms all...
What CLASSPATH Settings Are Needed to Run JUnit? It doesn't matter if you run your JUnit tests from ...