Parameter

  1. Primitive parameter : read only

class Data{int x;}

class Ex6_6 {
    public static void main(String[] args) {
        Data d = new Data();
        d.x = 10;
        System.out.prinln("main() : x = " +d.x);
        
        change(d.x);
        System.out.println("After changed(d.x)");
        System.out.println("main() : x =" + d.x);//x값 10 불변.
        
    }

    static void change(int x) {//primitive type : read only
        x = 1000;//only exist when change method is being executed
        //after change execution, change method and local variable in change method disappear from call stack
        System.out.println("change() : x = " + x);
    }
}
Primitive type parameter

2. Reference parameter : read & write

Reference type parameter
  • Reference type return

Reference type return

reference return type means return the address of object so that after copy method is ended, the d2 from copy method can be used in main method.

The two static methods, void main() {..} and Data copy(){..} are in same class. There is no reference type variable to get something from copy method. The reasons are 1.copy method is static method. 2. main and copy methods are in same class.

Static method can be used without creating object(reference type variable). Other normal method is used like below.

Last updated

Was this helpful?