update polymorphism example

This commit is contained in:
Oleksii Aleshchenko 2023-03-02 15:48:38 +02:00
parent 429bcc7b3d
commit f692ae7588
4 changed files with 31 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package encapsulationInheritancePolymorphism.polymorphism;
public class ElectricEngine extends Engine { public class ElectricEngine extends Engine {
private String batteryType; private String batteryType;
@Override
public int getPower() { public int getPower() {
return 20; return 20;
} }

View File

@ -3,6 +3,7 @@ package encapsulationInheritancePolymorphism.polymorphism;
public class FuelEngine extends Engine { public class FuelEngine extends Engine {
private String fuelType; private String fuelType;
@Override
public int getPower() { public int getPower() {
return 50; return 50;
} }

View File

@ -22,5 +22,17 @@ public class Main {
/*for (int i = 0; i < engines.length; i++) { /*for (int i = 0; i < engines.length; i++) {
System.out.println(engines[i].getPower()); System.out.println(engines[i].getPower());
}*/ }*/
// +
int a = 1;
int b = 1;
int c = a + b;
System.out.println(c);
String sA = "1";
String sB = "1";
String sC = sA + sB;
System.out.println(sC);
} }
} }

View File

@ -0,0 +1,17 @@
package encapsulationInheritancePolymorphism.polymorphism.overload;
public class MyClassForOverloadExample {
void myMethod(int a) {
System.out.println("Integer: " + a);
}
void myMethod(double a) {
System.out.println("Double: " + a);
}
public static void main(String[] args) {
MyClassForOverloadExample overload = new MyClassForOverloadExample();
overload.myMethod(1);
overload.myMethod(0.1);
}
}