Hi this is an extension to the discussion on topic overriding , hiding and dynamic method dispacth..
class Super
{
int a=2;
static int b=4;
Super()
{
method();
printone();
}
static void method()
{
System.out.println("Inside Super "+b+"\n");
}
void printone()
{
System.out.println("Inside Super "+a+"\n");
}
}
public class sub extends Super
{
int a=3; //***************************
void printone()
{
System.out.println("Inside Sub "+a);
}
static void method()
{
System.out.println("Inside Sub "+b+"\n");
}
public static void main(
String arg[])
{
sub s=new sub();
s.printone();
}
}
gives output
Inside Super b=4
Inside sub a=0
Inside sub a=3 well this is OK with respect to the priority of initialisation.. If the marked line is commented out output will be as follows
Inside Super b=4
Inside sub a=2
Inside sub a=2
It is said in earlier discussion that instance members are initialised to default values (even though it has got initialization expression ) and after the constructor return it's invocation, instance varianles will be initialised to those explicit values given in the initialisation expression..
but why it is happening in second case that it is printing a as 2 ans 2..
I am posting this topic on respective discussion also.. some body can expalin this elaborately and clearly..
thanks 'n regds.
vbreddy