Monday, December 6, 2010

Private final methods

If one class have one private final method so what happen if another class is try to overridden the same method in another class:
for reference check the below example

class Raptor{
private final void test(){
System.out.println("i am final of Raptor");
}
}

class Hawk extends Raptor {
public final void test(){
System.out.println("i am the final of Hawk");
}

public static void main(String[] args) {
Hawk hawk_obj = new Hawk();
hawk_obj.test();
}
}

Result:
compile and program may run the output is "i am the final of Hawk", because the test function is private and it'll never available in another class so the final method never be override in another class rule is not applicable.

No comments: