Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class P214_Inheritance {
- public static void main(String[] args) {
- A a = new B();
- System.out.println(a.f());
- B b = (B) a;
- System.out.println(b.f());
- }
- private static class A {
- int a = 1, b = 2;
- int f() {
- return a + b;
- }
- }
- private static class B extends A {
- int c = 3;
- @Override
- int f() {
- return super.f() + c;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement