mirror of
https://github.com/ASDjonok/OOP_IO-2x_2023.git
synced 2026-05-20 09:28:46 +03:00
add test polymorphism example
This commit is contained in:
@@ -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();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user