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
Question
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
Solution
The correct answer is Compilation error.
Here's why:
In the main method, an object of the class Marks is created and the function method is called using this object. However, the function method that is being called does not exist. The function method without parameters is private and cannot be accessed outside of the class. The function method with an int parameter is static and should be called on the class, not an instance of the class. Therefore, the program will not compile and a compilation error will occur.
Similar Questions
elect the correct answerWhat is the output of the following program?public class Test{ private String function(String temp, int data, int sum) { return ("CTC"); } private String function(String temp, int data) { return ("CodeTantraCode"); } public static void main(String[] args) { Test obj = new Test(); System.out.println(obj.function("CTC", 0, 20)); }}OptionsRuntime errorCompilation errorCTCCodeTantraCode
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 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
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
What 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
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.