Wednesday, 15 May 2013

Final Key word in java

In java we have final  varaible as well as final  method,when we declare varaible as final it's value never change through out the program and when we declare method as final such method can not be override.

syntax;
final int i=3.14;

here the value of i never change in program.



public class show{

        public final int no1;
        public final int no2;

        show(int first, int second) {
                no1= first;
                no2 = second;
        }

         
public class Myshow {
  private final int pi;
  public myshow() {
    ...
    pi = 3;
    ...
  }
}

No comments:

Post a Comment