Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import java.io.IOException;
  2.  
  3. public class A {
  4. public void test() throws IOException{
  5. System.out.println("test in A");
  6. }
  7. }
  8.  
  9. import java.io.IOException;
  10.  
  11. public class B extends A {
  12. @Override
  13. public void test() throws Exception{
  14. System.out.println("test in B");
  15. }
  16. }
  17.  
  18. public void test() throws IOException{//<--header of A
  19. System.out.println("test in B");//<--body of B
  20. //here i can throw wide Exception from IOException
  21. //because here is body of test in B.test method in B can throws Exception so compiler doesn't approve this version of code
  22. }
  23.  
  24. A a = new B(); //when compiler converts this line into bytecode
  25. //does it loads of method headers of A and method body's of B
  26. a.test()
  27.  
  28. A a = new B();
  29. try {
  30. a.test();
  31. } catch (IOExceoption e) {
  32. //do some specific handle for IOExceoption
  33. }
  34.  
  35. public class A {
  36. public void test() throws Exception {
  37. System.out.println("test in A");
  38. }
  39. }
  40. public class B extends A {
  41. @Override
  42. public void test() throws IOException{
  43. System.out.println("test in B");
  44. }
  45. }
  46.  
  47. A a = new B();
  48. try {
  49. a.test();
  50. } catch (Exception e) {
  51. //handle
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement