Java中的向下轉型
是的,變數可以透過轉換向下轉型為其較低範圍的替代品。但它可能會導致資料丟失。請參見以下示例 −
示例
public class Tester {
public static void main(String[] args) {
int a = 300;
byte b = (byte)a;
System.out.println(b);
}
}輸出
它將列印輸出為
44
廣告
是的,變數可以透過轉換向下轉型為其較低範圍的替代品。但它可能會導致資料丟失。請參見以下示例 −
public class Tester {
public static void main(String[] args) {
int a = 300;
byte b = (byte)a;
System.out.println(b);
}
}它將列印輸出為
44