Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.624 :

Posted: Sat Feb 15, 2014 4:36 pm
by aruna1982
in the trial exam, explanation has the following code. Doesn't m1 method in class a missing void?

Code: Select all

Another concept (although not related to this question but about static methods) is that static methods are never overridden. They are HIDDEN or SHADOWED just like static or non-static fields. For example,

class A
{
  int i = 10;
  public static m1(){  }
  public void m2() { }
}
class B extends A
{
  int i = 20;
  public static void m1() {  }
  public void m2() { }
}


Here, UNLIKE m2, m1() of B does not override m1() of A, it just shadows it, as proven by the following code: A a = new B(); System.out.println(a.i) //will print 10 instead of 20 a.m1(); //will call A's m1 a.m2(); //will call B's m2 as m2() is not static and so overrides A's m2()

Re: About Question com.enthuware.ets.scjp.v6.2.624 :

Posted: Sat Feb 15, 2014 8:37 pm
by admin
Yes, it is. Fixed.

thank you for your feedback!