Knowee
Questions
Features
Study Tools

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

Question

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

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the program will be "CodeTantraCode".

Here's the step by step explanation:

  1. The main method is the entry point of the program. It creates an object of the Test class and calls the function method on this object.

  2. The function method is overloaded, which means there are two methods with the same name but different parameter types. The Java compiler uses the types and number of parameters to determine which version of an overloaded method to execute.

  3. In the main method, the function method is called with an integer and a string as parameters. The compiler matches this with the function method that takes an integer as the first parameter and a string as the second parameter.

  4. Therefore, the function method that returns "CodeTantraCode" is executed and its result is printed to the console.

This problem has been solved

Similar Questions

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 answerPredict the output of following Java program.class codetantra {   public static void main(String[] args) {    for(int i = 0; 0; i++)    {      System.out.println("Hello");      break;    }   } } OptionsCompiler errorEmpty OutputHelloRuntime 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 code? class Name {     public static void main(String args[]) {          try {             int ct1 = 0;             int ct2 = 5;             int ct3 = ct2 / ct1;             System.out.print("Hello");         }         catch(Exception e) {             System.out.print("CodeTantra");         }      } }OptionsCodeTantraHelloHelloCodeTantraCompilation 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

1/3

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.