Down Casting in Java



Yes, a variable can be downcast to its lower range substitute by casting. It may lead to data loss although. See the example below −

Example

Live Demo

public class Tester {
 
   public static void main(String[] args) {
      int a = 300;
 
      byte b = (byte)a;
 
      System.out.println(b);
   }  
}

Output

It will print output as −

44
Updated on: 2020-03-12T10:34:57+05:30

162 Views

Kickstart Your Career

Get certified by completing the course

Get Started