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
Question
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
Solution
The output of the program will be "CTC".
Here's the step by step explanation:
- A new object of the class Test is created named obj.
- The function is called using the obj object with parameters 1.0 (which is a double) and 20 (which is an int).
- Since Java supports method overloading, it will choose the method that best fits the provided arguments. In this case, it will choose the function that accepts two double parameters because an int can be automatically converted to a double in Java (this is called automatic type conversion or type promotion).
- The function with two double parameters returns the string "CTC".
- This returned string "CTC" is then printed to the console.
Similar Questions
Select the correct answerWhat is the output of the following program? public class Test{ private String function(String temp, int data) { return ("CTC"); } private String function(int data, String temp) { return ("CodeTantraCode"); } public static void main(String[] args) { Test obj = new Test(); System.out.println(obj.function(4, "CTC")); }}OptionsCompilation errorCodeTantraCodeCTCRuntime error
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
Select the correct answerWhat 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
Select the correct answerWhat will be the output of the following Java program? class scopevariable { public static void main(String args[]) { int c; c = 15; { int d = 36; System.out.print(c + " " + d); } System.out.println(c + " " + d); } }Options5 6 55 6 5 6Runtime errorCompilation error
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
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.