Select the correct answerWhat is the output of the following program?public class Score{ public static void main(String[] args) { double data = 222.365; int value = data; System.out.println(data); }}Options222222.365Runtime errorCompilation error
Question
Select the correct answerWhat is the output of the following program?public class Score{ public static void main(String[] args) { double data = 222.365; int value = data; System.out.println(data); }}Options222222.365Runtime errorCompilation error
Solution
The correct answer is "Compilation error".
In Java, you cannot directly assign a value of a higher data type (in this case, double) to a variable of a lower data type (in this case, int) without explicit casting. The line "int value = data;" will cause a compilation error.
Similar Questions
elect the correct answerWhat is the output of the following program?public class Score{ public static void main(String[] args) { int value = 121; String var = (String)value; //line 1 String temp = "122"; int data = (int)temp; //line 2 System.out.println(data + var); }}OptionsCompilation error due to line 2Compilation error due to line 1243Compilation error due to line 1 and line 2
Select the correct answerWhat is the output of the following program?public class Score{ public static void main(String[] args) { double data = 222.423; int sum = 3; float value = 2.1f; System.out.println(data + sum + value); }}Options222222.423227.52299222.5
Select the correct answerWhat is the output of the following program?public class Score{ public static void main(String[] args) { System.out.println((125/50.0)*Integer.parseInt("10") + 70); }}Options95.080Compilation errorRuntime error
elect the correct answerWhat is the output of the following program? public class Test{ private String function(float i, int f) { return ("ctc"); } private String function(double i, double f) { return ("CTC"); } public static void main(String[] args) { Test obj = new Test(); System.out.println(obj.function(1., 20)); }}OptionsRuntime errorCompilation errorCTCCodeTantraCode
Select the correct answer What is the output of the following program? public class Marks{ private String function() { return ("CTC"); } public final static String function(int data) { return ("CodeTantraCode"); } public static void main(String[] args) { Marks obj = new Marks(); System.out.println(obj.function()); }}OptionsCTCRuntime errorCompilation errorNone of these
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.