Here is a simple example where I am inheriting the class property.
class Xyz
{
int a = 10;
}
public class Demo extends Xyz
{
int a = 5;
public static void main( String[] args )
{
Xyz z = new Demo();
System.out.println(z.a);
}
}
Since the object is of class Demo
is should print 5
but the output is 10
. What is the reason behind it?