Explain pass by reference and pass by value?

Answer Posted / ganesh nagalingam

***In Java, primitives and object references are passed by
value.***
The variable represents the bit information which is copied
to the parameter.

eg:primitive****
Say for primitives x=2, the value of 2 is represented in
bits and it is copied to the parameter variable.

eg:object reference***
Button b = new Button("hello");
Button c = b;
Similarly for object reference the bit value in the
reference is copied to the parameter reference. Thus both
references have the same value representing an object. The
object reference(bit representation) represents a way to
get to the object.

Is This Answer Correct ?    9 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can a constructor call the constructor of parent class?

802


what is singleton in java?

812


What are the rules for naming an array?

745


Can main() method in java can return any data?

913


Difference between a process and a program?

833


Variables used in a switch statement can be used with which datatypes?

749


What is the length of a string?

759


How many bits are used to represent unicode, ascii, utf-16, and utf-8 characters in java programming?

807


What is default exception handling in java?

779


How many bytes is double?

753


Do loops java?

772


What is an example of procedure?

743


How we can skip finally block of exception even if some exception occurs in the exception block in java?

733


Can we make main() thread as daemon?

849


What are the 8 primitive data types in java?

777