Why Do You Use Upcasting or Downcasting in Java ?

When we want to cast a Sub class to Super class, we use Upcasting. It is also known as widening. Upcasting is always allowed in Java.

When we want to cast a Super class to Sub class, we use Downcasting. It is also known as narrowing.

At times, Downcasting can throw the ClassCastException if it fails the type check.



You May Interest

What are the Popular Implementations of Deque in Java ?

Can We Use Thread.sleep Method For Real-time Processing in Java ?

What are the Advantages of Using JSP in Web Architecture ?

What are the Atomic Operations in Java ?

How Will You Use Other Java Files of Your Application in JSP Code ...