update polymorphism example
This commit is contained in:
parent
429bcc7b3d
commit
f692ae7588
|
@ -3,6 +3,7 @@ package encapsulationInheritancePolymorphism.polymorphism;
|
|||
public class ElectricEngine extends Engine {
|
||||
private String batteryType;
|
||||
|
||||
@Override
|
||||
public int getPower() {
|
||||
return 20;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package encapsulationInheritancePolymorphism.polymorphism;
|
|||
public class FuelEngine extends Engine {
|
||||
private String fuelType;
|
||||
|
||||
@Override
|
||||
public int getPower() {
|
||||
return 50;
|
||||
}
|
||||
|
|
|
@ -22,5 +22,17 @@ public class Main {
|
|||
/*for (int i = 0; i < engines.length; i++) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue