Page 1 of 1

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

Posted: Sun Nov 06, 2011 5:38 pm
by Johnny
public interface Automobile { String describe(); }
class FourWheeler implements Automobile
{
String name;
public String describe(){ return " 4 Wheeler " + name; }
}
class TwoWheeler extends FourWheeler
{
String name;
public String describe(){ return " 2 Wheeler " + name; }
}

---
When TwoWheeler inherits name variable from FourWheeler, why compiler doesn't complain about attempt of defining variable with same name? Thanks in advance.

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

Posted: Wed Mar 14, 2012 5:09 am
by Pablo Reyes
Why should it? It's called hiding (http://www.xyzws.com/Javafaq/what-is-va ... adowing/15).