What will be the output of the following Java code? class codetantra { public static void main(String args[]) { double m = 295.30; int n = 330; byte o = (byte) m; byte p = (byte) n; System.out.println(o + " " + p); } }Options39 7438 7395 300295.30 330
Question
What will be the output of the following Java code? class codetantra { public static void main(String args[]) { double m = 295.30; int n = 330; byte o = (byte) m; byte p = (byte) n; System.out.println(o + " " + p); } }Options39 7438 7395 300295.30 330
Solution
The output of the given Java code will be "39 74".
Here's the step-by-step explanation:
- The code declares a double variable 'm' and assigns it the value 295.30.
- It then declares an integer variable 'n' and assigns it the value 330.
- The code then declares a byte variable 'o' and assigns it the value of 'm' cast to a byte. The byte data type in Java has a maximum value of 127, so when 295.30 is cast to a byte, it wraps around to 39.
- Similarly, it declares a byte variable 'p' and assigns it the value of 'n' cast to a byte. When 330 is cast to a byte, it wraps around to 74.
- Finally, the code prints the values of 'o' and 'p', which are 39 and 74 respectively.
Similar Questions
What will be the output of the following Java code? class codetantra { public static void main(String args[]) { char a = 'A'; char b = 76; b++; a++; System.out.println(a + " " + b); } }OptionsC NB MD OA M
Select the correct answerPredict the output of the following program.class codetantra{ public static void main(String[] args) { Double object = new Double("2.4"); int p = object.intValue(); byte q = object.byteValue(); float r = object.floatValue(); double s = object.doubleValue(); System.out.println(p + q + r + s ); }}Options8.888.800000095367432
Select the correct answerWhat will be the output of the following Java program, if we run as “java Codetantra 4 7 9”? class Codetantra { public static void main(String [] args) { String [][] argument = new String[2][2]; int a; argument[0] = args; a = argument[0].length; for (int b = 0; b < a; b++) System.out.print(" " + argument[0][b]); } }Options4 04 44 0 94 7 9
What will be the output of the following Java code? class Codetantra { final public int output(int x, int y) { return 1; } } class Program extends Codetantra { public int output(int x, int y) { return 2; } } public class result { public static void main(String args[]) { Program object = new Program(); System.out.print("y is " + y.output(0, 1)); } }Optionsy is : 0y is : 1Compilation ErrorAn exception is thrown at runtime
What will be the output of the following Java program? package pkg; class output {public static void main(String args[]) { StringBuffer s1 = new StringBuffer("Hello"); s1.setCharAt(1, x); System.out.println(s1); } }
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.