How to Narrow Casting in Java


In this example, we will learn you how to narrow Casting in Java.

Source Code

package com.beginner.examples;

public class NarrowCasting {
  public static void main(String[] args) {
    float f = 10.16f;
    int i = (int) f; // narrow casting: float to int
    System.out.println(f);
    System.out.println(i);
  }
}

Output:

10.16
10
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments