class Animal { void sound() { System.out.println("Animal makes a sound"); } } class Dog extends Animal { void sound() { System.out.println("Dog barks"); } } public class UpcastingExample { public static void main(String[] args) { Animal animal = new Dog(); // Upcasting animal.sound(); } }