add test polymorphism example
This commit is contained in:
parent
484bef389b
commit
e41e64369b
|
@ -0,0 +1,7 @@
|
|||
package test.one;
|
||||
|
||||
public class A implements MyMethodInterface {
|
||||
public void myMethod() {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package test.one;
|
||||
|
||||
public class B implements MyMethodInterface {
|
||||
public void myMethod() {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package test.one;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Object[] objects = {
|
||||
new A(),
|
||||
new B(),
|
||||
};
|
||||
for (Object object : objects) {
|
||||
((MyMethodInterface)object).myMethod();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package test.one;
|
||||
|
||||
public interface MyMethodInterface {
|
||||
void myMethod();
|
||||
}
|
Loading…
Reference in New Issue