class Animal {
String color = "white";
}
class Dog extends Animal {
void printColor() {
System.out.println("This Color: " + color); //prints color of Dog class
System.out.println("Parent Color: " + super.color); //prints color of Animal class
}
}
class TestSuper1 {
public static void main(String args[]) {
Dog d = new Dog();
d.color = "black";
d.printColor();
}
}
In the output "Parent Color" is printing "black" which confusing me. It should be "white" right since I have changed the color of Child object only ? Could anybody please explain me the reason.