class_inheritance_methods.carbon 712 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. package ExplorerTest api;
  7. base class C {
  8. fn BasePrint(v: i32) {
  9. Print("Class {0}", v);
  10. }
  11. fn Method1[self: Self]() {
  12. self.BasePrint(self.value_c);
  13. }
  14. var value_c: i32;
  15. }
  16. class D {
  17. extend base: C;
  18. fn Method2[self: Self]() {
  19. self.BasePrint(self.value_d);
  20. }
  21. var value_d: i32;
  22. }
  23. fn Main() -> i32 {
  24. var d: D = {.base = {.value_c = 1}, .value_d = 2};
  25. d.Method1();
  26. d.Method2();
  27. return 0;
  28. }
  29. // CHECK:STDOUT: Class 1
  30. // CHECK:STDOUT: Class 2
  31. // CHECK:STDOUT: result: 0