mirror of
https://github.com/ASDjonok/OOP_IO-2x_2023.git
synced 2025-06-07 22:49:24 +03:00
add test polymorphism example
This commit is contained in:
parent
484bef389b
commit
e41e64369b
7
src/test/one/A.java
Normal file
7
src/test/one/A.java
Normal file
@ -0,0 +1,7 @@
|
||||
package test.one;
|
||||
|
||||
public class A implements MyMethodInterface {
|
||||
public void myMethod() {
|
||||
|
||||
}
|
||||
}
|
7
src/test/one/B.java
Normal file
7
src/test/one/B.java
Normal file
@ -0,0 +1,7 @@
|
||||
package test.one;
|
||||
|
||||
public class B implements MyMethodInterface {
|
||||
public void myMethod() {
|
||||
|
||||
}
|
||||
}
|
13
src/test/one/Main.java
Normal file
13
src/test/one/Main.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
5
src/test/one/MyMethodInterface.java
Normal file
5
src/test/one/MyMethodInterface.java
Normal file
@ -0,0 +1,5 @@
|
||||
package test.one;
|
||||
|
||||
public interface MyMethodInterface {
|
||||
void myMethod();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user