class_inheritance_methods.carbon 711 B

12345678910111213141516171819202122232425262728293031323334353637
  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 {
  20. extend base: C;
  21. fn Method2[self: Self]() {
  22. self.BasePrint(self.value_d);
  23. }
  24. var value_d: i32;
  25. }
  26. fn Main() -> i32 {
  27. var d: D = {.base = {.value_c = 1}, .value_d = 2};
  28. d.Method1();
  29. d.Method2();
  30. return 0;
  31. }