int) variables into the long variables.class Main {
public static void main(String[] args) {
// create int variables
int a = 25;
int b = 34;
// convert int into long
// using typecasting
long c = a;
long d = b;
System.out.println(c); // 25
System.out.println(d); // 34
}
}25
34long. It is because long is a higher data type and int is a lower data type.int to long. This is called widening typecasting. int type variable into an object of the Long class. For example,class Main {
public static void main(String[] args) {
// create int variables
int a = 251;
// convert to an object of Long
// using valueOf()
Long obj = Long.valueOf(a);
System.out.println(obj); // 251
}
}251Long.valueOf() method to convert the variable a into an object of Long.Long is a wrapper class in Java.