Java support call by reference (pass by reference) ?

Answer Posted / sarju001

yes java support call by reference only using StringBuffer
class.

Here, is an example of call by reference

public class PassByReference
{
public static void passref(StringBuffer s)
{
s = s.insert(8, "j2ee & ");
System.out.println(s);
}
public static void main(String[] args)
{
StringBuffer str = new StringBuffer("Welcome java
program");

System.out.println(str);

passref(str);

System.out.println(str);
}
}


output :-

Welcome java program
Welcome j2ee & java program
Welcome j2ee & java program

Is This Answer Correct ?    9 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do singleton patterns work?

609


Why is singleton instance static?

600


What is communist flag?

649


If try block is successfully executed, Then Is Finally block executed?

707


Implement 2 stacks with just 1 array. The stack routines must not indicate overflow unless every slot in array is used.

920






What is an example of a conditional statement?

656


Why there is no call by reference in java?

582


What is string and its types?

721


What is arrays sort in java?

654


Is arraylist ordered in java?

663


When a lot of changes are required in data, which one should be a preference to be used? String or stringbuffer?

876


Difference between this() and super() in java ?

692


Can I use % with real numbers?

653


What is the biggest integer?

670


Can there be an abstract method without an abstract class?

608