class_inheritance_methods.carbon 703 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. //
  5. // AUTOUPDATE
  6. // CHECK:STDOUT: Class 1
  7. // CHECK:STDOUT: Class 2
  8. // CHECK:STDOUT: result: 0
  9. package ExplorerTest api;
  10. base class C {
  11. fn BasePrint(v: i32) {
  12. Print("Class {0}", v);
  13. }
  14. fn Method1[self: Self]() {
  15. self.BasePrint(self.value_c);
  16. }
  17. var value_c: i32;
  18. }
  19. class D extends C {
  20. fn Method2[self: Self]() {
  21. self.BasePrint(self.value_d);
  22. }
  23. var value_d: i32;
  24. }
  25. fn Main() -> i32 {
  26. var d: D = {.base = {.value_c = 1}, .value_d = 2};
  27. d.Method1();
  28. d.Method2();
  29. return 0;
  30. }