Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- public class A {
- public void test() throws IOException{
- System.out.println("test in A");
- }
- }
- import java.io.IOException;
- public class B extends A {
- @Override
- public void test() throws Exception{
- System.out.println("test in B");
- }
- }
- public void test() throws IOException{//<--header of A
- System.out.println("test in B");//<--body of B
- //here i can throw wide Exception from IOException
- //because here is body of test in B.test method in B can throws Exception so compiler doesn't approve this version of code
- }
- A a = new B(); //when compiler converts this line into bytecode
- //does it loads of method headers of A and method body's of B
- a.test()
- A a = new B();
- try {
- a.test();
- } catch (IOExceoption e) {
- //do some specific handle for IOExceoption
- }
- public class A {
- public void test() throws Exception {
- System.out.println("test in A");
- }
- }
- public class B extends A {
- @Override
- public void test() throws IOException{
- System.out.println("test in B");
- }
- }
- A a = new B();
- try {
- a.test();
- } catch (Exception e) {
- //handle
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement