Upcasting Vs Downcasting in Java
class Vehicle { int maxSpeed = 250; public void printMaxSpeed() { System.out.println(“Max speed: ” + maxSpeed); } } class Car extends Vehicle { int maxSpeed = 300; @Override public void printMaxSpeed() { System.out.println(“Max speed: ” + maxSpeed); } } class Test { public static void main(String[] args) { Vehicle vehicle = new Car(); // upcasting…
Read More Upcasting Vs Downcasting in Java