parent p = new child()
Quandchild c = new child()
Mémorandum de ce qui est différent
class Parent{
int a = 1;
static int b = 2;
String medhod1() {
return "parent method1";
}
static String medhod2() {
return "parent method2";
}
}
class Child extends Parent{
int a = 10;
int b = 20;
@Override
String medhod1() {
return "child method1";
}
static String medhod2() {
return "child method2";
}
}
Parent parent = new Child();
System.out.println(parent.a); // =>1 ・ ・ ・ ★
System.out.println(parent.b); // =>2 ・ ・ ・ ★
System.out.println(parent.medhod1()); // =>méthode enfant1 ・ ・ ・ ★
System.out.println(parent.medhod2()); // => parent method2
Child child = new Child();
System.out.println(child.a); // => 10
System.out.println(child.b); // => 20
System.out.println(child.medhod1()); // => child method1
System.out.println(child.medhod2()); // => child method1
Recommended Posts