View RSS Feed

Java Object

Parameter Names

Rate this Entry
by , 04-26-2012 at 05:18 PM (513 Views)
When a parameter is declard to a constructor or a method, it means that a name is provided for that parameter. Within method body, this name is used so that for referring to the argument that has passed-in.
Parameterís name shall be unique, in its scope. It is not possible to be similar to the other parameterís name for the same constructor or method, or the local variableís name in constructor or method.

Parameter may be having similar name just like that of classís field. In such a case it is said that parameter will be shadow field. This field shadowing may make it difficult to read your code and it is typically used in methods & construcotrs which set specific field. Let us consider the given Circle class & given setOrigin method:
Java Code:
public class Circle {
    private int x, y, radius;
    public void setOrigin(int x, int y) {
There are 3 fields in circle class (x, y & radius). There are 2 parameters in setOrigin method out of which each has similar name just like one of fields. Fields sharing its names are shadowed by each method. Therefore, simple names usage like x or y in method body refers to parameter & not the field. Field can be accessed by using a qualified name.

Submit "Parameter Names" to Facebook Submit "Parameter Names" to Digg Submit "Parameter Names" to Submit "Parameter Names" to StumbleUpon Submit "Parameter Names" to Google