MCQ Single Best Answer Not Set

QWhat is the output for the below code?
import java.io.FileNotFoundException;
class A{
      public void printName() throws FileNotFoundException{
            System.out.println("Value-A");
      }
}
class B extends A{
      public void printName() throws NullPointerException{
            System.out.println("Name-B");
      }
}
public class Test{
      public static void main (String[] args) throws Exception{
            A a = new B();
            a.printName();
      }
}

ID: #2330 Java Exception MCQ 833 views
Question Info
#2330Q ID
Not SetDifficulty
Java Exception MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A Value-A
  • B Compilation fails-Exception NullPointerException is not compatible with throws clause in A.printName()
  • C Name-B
  • D Compilation succeed but no output
Correct Answer: Option C

Explanation

Name-B

Share This Question

Challenge a friend or share with your study group.