Explanation
This Java code is a simple program designed to calculate and display the sum of two predefined integer numbers.
The program starts by defining a class named prog2. In Java, all code resides within classes. Inside this class, there is a special method called main. The main method is the entry point for any Java application – when you run the program, the Java Virtual Machine (JVM) looks for and executes the code within this main method.
Inside the main method, three integer variables are declared: a, b, and c. Variables a and b are immediately initialized with values: a gets 10 and b gets 2. Variable c is declared but not yet assigned a value.
Next, an arithmetic operation c = a + b; is performed. This statement calculates the sum of the current values of a (which is 10) and b (which is 2), resulting in 12. This result (12) is then assigned to the variable c.
Finally, the line System.out.println("Sum is "+ c); prints the result to the console. System.out.println() is a standard Java method used for displaying output. It combines the string literal "Sum is " with the numerical value stored in c (which is 12) using string concatenation, and then prints the entire combined string followed by a new line.