Very important Java developer interview question on exception handling #java #tcs #coding

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

Java Developer Interview round 2 for MPHASIS | Interview live recording for Java Developer part 10

LoggedoutBros
Автор

Both are checked exception but io is parent class of file not found so no error will come.
Opposite will give error.

youtubeaddict
Автор

Yes, the code should compile without any issues. In Java, the child class can declare a checked exception that is a subclass of the exception declared by its parent class. `FileNotFoundException` is a subclass of `IOException`, so this relationship is valid.

Here's an example:

```java
import java.io.IOException;
import

class Parent {
void example() throws IOException {
// code that may throw IOException
}
}

class Child extends Parent {
// It's okay to narrow the exception type in the overridden method
void example() throws FileNotFoundException {
// code that may throw FileNotFoundException
}
}
```

In this example, the `Child` class overrides the `example` method from the `Parent` class, and it narrows the exception type to `FileNotFoundException`. This is allowed in Java, and the code should compile successfully.

aysk_
Автор

In case of checked exception only either parent will through same as child or its parent exception both will work .. and here ioexception is parent of filenotfoundexception so it will work 😊

aseshkumar
Автор

Both the exception are the checked exception which means both the exception are checked by compile and becoz of that there will be a compile time error.🙂

subhasishhansda
Автор

is the answer right? is it not the other way?

samjackson
Автор

No error...we will achieve overriding in this case.

anubhavchauhan
Автор

Vice versa is true... will throw ompile erro r

kamallochanpadhi