Upcasting and Downcasting in Java (Simple Explanation)
java
dev.to
When working with inheritance in Java, you’ll often hear two terms: Upcasting and Downcasting. Don’t worry — it’s not as complicated as it sounds. First, let’s understand the idea In Java, a child class inherits from a parent class. Example: class Animal { void sound() { System.out.println("Animal makes a sound"); } } class Dog extends Animal { void bark() { System.out.println("Dog barks"); } } Here: Animal -> Parent class Dog -> Child class What