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