menu_book Course Curriculum (Java) expand_more
Numeric promotion
Learn Numeric promotion in Java with a focused explanation, a dedicated runnable example, and a relevant engineering boundary.
Numeric promotion is an atomic Java topic in Java Program Foundations. This lesson isolates the construct so you can see what it changes, what value or state it produces, and which surrounding rules matter.
The example below is written specifically for Numeric promotion. Run it once as shown, trace the observable result, then modify the relevant operand, argument, input, or state. Do not replace the construct with a neighboring feature: the purpose is to learn this exact behavior in context.
Topic-specific example
public class Main {
public static void main(String[] args) throws Exception {
byte a=10,b=20; int sum = a + b; System.out.println(((Object)sum).getClass().getSimpleName());
}
}
Check the numeric type and boundary behavior of Numeric promotion. Division, rounding, promotion, and negative operands can change the result in ways that are easy to miss.