Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Tester {
- public static abstract class A {
- abstract void work();
- void huh(Tester t) {
- t.make(this);
- }
- }
- public static class B extends A {
- @Override
- void work() {
- System.out.println("B");
- }
- }
- public static class C extends A {
- @Override
- void work() {
- System.out.println("C");
- }
- }
- public static class BB extends B {
- @Override
- void work() {
- System.out.println("BB");
- }
- }
- void make(A a) {
- a.work();
- System.out.println("A generic");
- }
- void make(B b) {
- b.work();
- System.out.println("B overload");
- }
- void make(BB b) {
- b.work();
- System.out.println("BB overload");
- }
- void make(C c) {
- c.work();
- System.out.println("C overload");
- }
- public static class Tester2 extends Tester {
- @Override
- void make(A a) {
- super.make(a);
- System.out.println("Tester2");
- }
- @Override
- void make(B b) {
- super.make(b);
- System.out.println("Tester2");
- }
- @Override
- void make(BB b) {
- super.make(b);
- System.out.println("Tester2");
- }
- @Override
- void make(C c) {
- super.make(c);
- System.out.println("Tester2");
- }
- }
- public static void main(String[] args) {
- Tester t = new Tester();
- Tester t2 = new Tester2();
- B b = new B();
- BB bb = new BB();
- C c = new C();
- A ab = new B();
- A abb = new BB();
- A ac = new C();
- B bbb = new BB();
- t.make(b);
- t.make(bb);
- t.make(c);
- System.out.println("\n");
- t.make(ab);
- t.make(abb);
- t.make(ac);
- System.out.println("\n");
- t.make(bbb);
- System.out.println("\n");
- b.huh(t);
- bb.huh(t);
- c.huh(t);
- System.out.println("\n");
- b.huh(t2);
- bb.huh(t2);
- c.huh(t2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement