Knowee
Questions
Features
Study Tools

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

Question

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

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

Solution

The correct answer is "Compilation Error".

The reason is that in Java, a method declared as final in the superclass cannot be overridden in the subclass. In the given code, the method "output" is declared as final in the superclass "Codetantra". Therefore, attempting to override this method in the subclass "Program" will result in a compilation error.

Similar Questions

e 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));      }   }

Select the correct answerWhat will be the output of the following Java program? class CT {    public static void main(String args[]) {     try {       System.out.print("Codetantra" + " " + 1 / 0);      }     catch(ArithmeticException e) {    System.out.print("World");          }   } }OptionsCodetantraCodetantraWorldCodetantra WorldWorld

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 = ct1 / ct2;               System.out.print("Hello");           }           catch(Exception e)            {               System.out.print("Codetantra");           }         }    }OptionsCodetantraHelloHelloCodetantraCompilation Error

Select the correct answerWhat will be the output of the given Java program? abstract class java {    int x;    abstract void display(); }     class method extends java {     int y;     void display() {        System.out.println(y);     } }     class Abstract_demo {     public static void main(String args[]) {         method obj = new method();         obj.y = 1;         obj.display();         } }OptionsRuntime Error10Compilation 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

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.