Advertisement
lobaev

Untitled

Feb 17th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. public class P214_Inheritance {
  2.  
  3. public static void main(String[] args) {
  4. A a = new B();
  5. System.out.println(a.f());
  6. B b = (B) a;
  7. System.out.println(b.f());
  8. }
  9.  
  10. private static class A {
  11.  
  12. int a = 1, b = 2;
  13.  
  14. int f() {
  15. return a + b;
  16. }
  17.  
  18. }
  19.  
  20. private static class B extends A {
  21.  
  22. int c = 3;
  23.  
  24. @Override
  25. int f() {
  26. return super.f() + c;
  27. }
  28.  
  29. }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement