ExamVeda
Login
Home
This question belongs to Java Program Exceptions
Exceptions
?

What will be the result after compiling this code?
class SuperClass{
      public int doIt(String str, Integer... data)throws Exception{
            String signature = "(String, Integer[])";
            System.out.println(str + " " + signature);
            return 1;
      }
}

public class Test extends SuperClass{
      public int doIt(String str, Integer... data){
            String signature = "(String, Integer[])";
            System.out.println("Overridden: " + str + " " +signature);
            return 0;
      }

      public static void main(String... args){
            SuperClass sb = new Test();
            sb.doIt("hello", 3);
      }
}

Answer & Solution
Correct Answer: Option C

Exceptions must be caught or declared to be thrown.

Examveda
Question posted by Examveda
Community

Join the Discussion

3 Comments
Sachin Sude
Sachin Sude 4 years ago
In this code everything is correct. only main method didn't handle exception throws by do it method.
because of that answer is compile time error.
if we modify main() throws Exception then we will get an output that is :Overridden: hello (String, Integer[])
Yogesh Sharma
Yogesh Sharma 4 years ago
As we are passing base class reference into child class object, so child class object will call base class "doIt" method.
Latika Bajaj
Latika Bajaj 9 years ago
please provide the well detailed solution by which we can understand easily.