1. Question 1th
1 classBase {2 Public voidmethod () {3System.out.print ("Base method"));4 }5 }6 7 classChildextendsBase {8 Public voidMethodB () {9System.out.print ("Child MethodB");Ten } One } A - classSample { - Public Static voidMain (string[] args) { theBase base =NewChild (); - Base.methodb (); - } -}
A. Base method
B. Child MethodB
C. Base method Child MethodB
D. Compilation errors
2. Question 2nd
1 classPerson {2 intA;3 Public intChangeintm) {4 returnm;5 }6 }7 8 Public classTeacherextendsPerson {9 Public intb;Ten Public Static voidMain (string[] args) { OnePerson p =NewPerson (); ATeacher T =NewTeacher (); - inti; -______//fill in the code here the } -}
A.i=b;
B.i=a;
C.i=p.change (30);
d.i=t.b;
3.
Attention:
(1) For member variables: compile look left , run look left ;
(2) For member method: compile look left , run look right ;
(3) Question 1th: The parent class refers to a subclass that can only invoke a method inherited from a parent class or a subclass to override a method inherited from a parent class;
Question 2nd: Static methods cannot invoke non-static members, static members belong to classes, main belongs to subclasses, it is also methods, but static methods of static, only static variables can be called. Therefore,int A and int b
are not directly called directly in main .
Java Fundamentals Hardening 11: Two basic problems of polymorphism