Overwriting the fields of a superclass within a subclass

时间:2018-03-22 23:30:31

标签: java inheritance final

Lets say I have a superclass Test1

public class Test1{
  public int foo;

  public void bar(final Integer value){
    foo = 0;
  }
}

And the subclass Test2

public class Test2 extends Test1{

  public void bar(final Integer value){
    foo = value;
  }
}

1) What does final in the class Test2 mean? And what does declaring a parameter final do and what would be the purpose? Does this only mean, that the parameter can not change within the method?

2) If I call the method bar which was overwritten in Test2, does it only change the inheritated field foo of Test1 or would this change the the fields in of Test2 as well as Test1?

0 个答案:

没有答案
相关问题