Given below the sample code :
1 class A1{
2 public void process() { System.out.print("Inside A1 "); }}
3 class B extends A1{
4 public void process() throws IOException{
5 super.process();
6 System.out.print("Inside B ");
7 throw new IOException();
8 }
9 public static void main(String[] args){
10 try { new B().process(); }
11 catch (IOException e) { System.out.println("Exception is caught "); }}}
How can we correct the above code?
1.By adding "throws IOException" at line 2.
2. By removing "throws IOException" at line 2.
3.No need of correction.
4.By adding "import java.io.*;" at line 1.
(1)&(4)
Overridden method has not "throws IOException"
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.