Knowee
Questions
Features
Study Tools

Problem statementSend feedbackWhat is the output of the following code?public class Solution { public int getSum(int a, int b) { int sum = a + b; } public static void main(String args[]) { Solution obj = new Solution(); System.out.println(obj.getSum(10, 20)); } }Options: Pick one correct answer from below30Runtime errorCompilation errorNone of the above

Question

Problem statementSend feedbackWhat is the output of the following code?public class Solution { public int getSum(int a, int b) { int sum = a + b; } public static void main(String args[]) { Solution obj = new Solution(); System.out.println(obj.getSum(10, 20)); } }Options: Pick one correct answer from below30Runtime errorCompilation errorNone of the above

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

Solution

The correct answer is Compilation error.

The method getSum() is supposed to return an integer value, but there is no return statement in the method. Therefore, the code will not compile.

Similar Questions

Select the correct answerWhat will be the output of the following Java program? class CT {  public static void main(String args[]) {     try {      int a, sum;      sum = 10;      for (a = -1; a < 3; ++a)        sum = (sum / a);    }    catch(ArithmeticException e) {  System.out.print("0");        }     System.out.print(sum);  } }Options050Compilation ErrorRuntime Error

What is the output of the following code?public class Solution { static int x = 10; public static void main(String args[]) { System.out.println(x); } }Options: Pick one correct answer from below100Compilation errorRuntime error

What will be the output of the following Java program?class control_statements  {    public static void main(String args[])     {          int sum = 0;       for (int u = 5, v = 5; u < 10 & v < 10; ++u, v = u + 1)         sum += u;     System.out.println(sum);    }   }Options261015compilation error

Select the correct answerWhat will be the output of the following Java program? class CT {  public static void main(String args[]) {     try {      int x, y;      y = 0;      x = 5 / y;      System.out.print("A");    }    catch(ArithmeticException e) {  System.out.print("B");        }  } }OptionsBACompilation ErrorRuntime 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

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.