KIO
Kreative Ideen online
Parameter and arguments

Parameter and arguments

A method uses parameters. A caller passes arguments.

Arguments are the things you pass into the methods. An argument (a value like 2, “Foo”, or a reference to a Dog) lands face-down into a… wait for it… parameter. And a parameter is nothing more than a local variable. A variable with a type and a name, that can be used inside the body of the method.

[php] class livingroom{ public static void main(String[] args){ DVDPLAYER objdvdpl = new DVDPLAYER (); objdvdpl.playmovie("Star wars"); } } public class DVDPLAYER{ void playmovie(String title){ String localtitle = title; startplaying(localtitle ); } } [/php]

Declare an int variable and assign it the value ‘7’.
The bit pattern for 7 goes into the variable named x.

Declare a method with an int parameter named z. Call the go() method, passing the variable x as the argument. The bits in x are copied, and the copy lands in z. Change the value of z inside the method.

The value of x doesn’t change!

The argument passed to the z parameter was only a copy of x.

The method can’t change the bits that were in the calling variable x.

Leave a Reply

Your email address will not be published. Required fields are marked *