Compare commits

..

3 Commits

Author SHA1 Message Date
Oleksii Aleshchenko 9b871b6a42 Merge remote-tracking branch 'origin/master' 2023-04-27 16:08:25 +03:00
Oleksii Aleshchenko e41e64369b add test polymorphism example 2023-04-27 16:08:09 +03:00
Oleksii Aleshchenko 484bef389b upd lab3 2023-04-27 15:57:01 +03:00
5 changed files with 69 additions and 0 deletions

View File

@ -1,10 +1,47 @@
public class Lab3 {
private static final int REPETITION_NUMBER = 10;
public static void main(String[] args) {
StringBuilder result = new StringBuilder();
for (int i = 0; i < REPETITION_NUMBER; i++) {
// result += Integer.toString(i);
// result += String.valueOf(i);
result.append(i);
}
/*float f = 1.1f;
double d = 2.2;
// f = (float) (f + d);
f += d;*/
String s = "ASD";
StringBuilder stringBuilder = new StringBuilder("ASD");
StringBuffer stringBuffer = new StringBuffer("ASD");
stringBuilder.append("A");
System.out.println(s.length());
System.out.println(stringBuilder.length());
System.out.println(stringBuffer.length());
System.out.println(s.endsWith("D"));
// System.out.println(stringBuilder.substring(stringBuilder.length() - 1).equals("A"));
System.out.println("A".equals(stringBuilder.substring(stringBuilder.length() - 1)));
System.out.println("A".equals(stringBuffer.substring(stringBuffer.length() - 1)));
String sNull = null;
System.out.println("A".equals(sNull));
System.out.println(sNull.equals("A"));
System.out.println(s.substring(2));
System.out.println(s.contains("AS"));
System.out.println(s.indexOf('a'));
// System.out.println(s.charAt(-1));
System.out.println("s.equalsIgnoreCase(\"AsD\") = " + s.equalsIgnoreCase("AsD"));
String s2 = s;
System.out.println("s2 = " + s2);

7
src/test/one/A.java Normal file
View File

@ -0,0 +1,7 @@
package test.one;
public class A implements MyMethodInterface {
public void myMethod() {
}
}

7
src/test/one/B.java Normal file
View File

@ -0,0 +1,7 @@
package test.one;
public class B implements MyMethodInterface {
public void myMethod() {
}
}

13
src/test/one/Main.java Normal file
View 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();
}
}
}

View File

@ -0,0 +1,5 @@
package test.one;
public interface MyMethodInterface {
void myMethod();
}