final keyword

Discussion in 'Serialization' started by Sudhanshu306, May 11, 2015.

  1. Sudhanshu306

    Sudhanshu306 New Member

    Can we use final for passed parameter?
  2. cool_one368

    cool_one368 New Member

    Very Good Question Indeed. Surprised to not to see the answer of this.

    For this we will take an example of a setter method. Please see the same below:

    public void setTest(String test) {
        test = test;
    Now suppose i forgot to add the "This" keyword over here. What will happen here is the variable that you are trying to set here will not be set. Now if i Add the final keyword on the parameter. This would give me a compile time error and I will get to know that there is something wrong here. Which helps in understanding. Hope it helps.
  3. anneroberts

    anneroberts Member

    The final keyword in java is used to restrict the user. The java final keyword can be used in many context. Final can be:

    1. variable
    2. method
    3. class.

Share This Page