Hi,
I am expecting output from following code as 10 But it gives output of 5. Can anybody tell me why this.id is returning parent class value? My understanding is by default you will have getId() which in thurn returns this.id.So when Ihave created Child c=new Child() , it should look into child class to access that method and should return value of child class itself but it is returning parent class value. I m too much confused. Kindly guide me.
[code]
Class Parent{
private int id=5;
public int getId(){
return this.id;
}
}
Class child extends Parent{
private int id=10;
public static void main(string []ar){
Child c = new Child();
System.out.println(c.getId());
}
}
[/code]