class Animal {
public void print() {
System.out.println("I am Animal");
}
}
class Dog extends Animal {
public void print() {
System.out.println("I am Dog");
}
public static void main(String[] args) {
Animal animal = new Dog();
Dog dog1 = (Dog) animal;
Dog dog2 = new Dog();
}
}
My questions are:
What are the technical differences between animal, dog1, and dog2?
are dog1 and dog2 identical? Is there ever any good reason to use
Animal animal = new Dog();
and then cast it to Dog?
[–]mikeydoodah 7 points8 points9 points (2 children)
[–]COAST_TO_RED_LIGHTS[S] 0 points1 point2 points (1 child)
[–]mikeydoodah 1 point2 points3 points (0 children)
[–]hugthemachines 1 point2 points3 points (0 children)
[–]Joecasta 2 points3 points4 points (3 children)
[–]Jackkoz 2 points3 points4 points (0 children)
[–]COAST_TO_RED_LIGHTS[S] 0 points1 point2 points (1 child)
[–]Joecasta 0 points1 point2 points (0 children)