next up previous
Next: Static or Class Variables Up: Varieties of Variables Previous: Local vs. Instance Variables

Method Parameters

How do method parameters fit into all of this?

Well, method parameters are the names of argument values which are passed to methods. Just like local variables, the values of method parameters live on the run-time stack, and exist for the duration of the method. The scope of a method parameter is the block that contains the method. Therefore, a method parameter is just like a local variable that is declared at the top of a method and whose containing block is the block that contains the method.

Since we don't have to do anything special other than declare local variables within a method and declare method parameters in the method declaration (which is within the class definition) in order for memory to be allocated, these are called automatic variables. This is in contrast to instance variables, for example. In the case of instance variables, we have to instantiate an object to have memory allocated for them. For example,


Student s1 = new Student();

allocates storage for all the member variables declared within the class definition for Student.


next up previous
Next: Static or Class Variables Up: Varieties of Variables Previous: Local vs. Instance Variables
Chris Trendall
Copyright ©Chris Trendall, 2001. All rights reserved.

2001-12-09