Академический Документы
Профессиональный Документы
Культура Документы
01. class A {
02. void f() {
03. System.out.print("A.f() called");
04. }
05. }
06.
07. class B extends A {
08. void f() {
09. System.out.println("B.f() called");
10. }
11. }
12.
13. public class Test {
14. static void getType(A a) {
15. System.out.print("Type A ");
16. }
17.
18. static void getType(B b) {
19. System.out.print("Type B ");
20. }
21.
22. public static void main(String[] args) {
23. A a = new B();
24. getType(a);
25. a.f();
26. }
27. }
01. class A {
02. String s = "A";
03. public String getName() {
04. return s;
05. }
06. }
07.
08. class B extends A {
09. String s = "B";
10. public String getName() {
11. return s;
12. }
13. }
14.
15. public class Test extends B {
16. String s = "C";
17. public static void main(String[] args) {
18. A a = new Test();
19. System.out.println(a.getName());
20. }
21. }