소스 검색

Merge pull request #332 from RobLoach/patch-1

Added class inheritance documentation
Marco Bambini 5 년 전
부모
커밋
09e6ef4a8f
1개의 변경된 파일24개의 추가작업 그리고 0개의 파일을 삭제
  1. 24 0
      docs/class.md

+ 24 - 0
docs/class.md

@@ -141,5 +141,29 @@ There are many cases where nested classes can lead to more readable and maintain
 	}
 ```
 
+### Inheritance
+Single class inheritance is supported in Gravity.
+```swift
+class Bird {
+	func talk() {
+		System.print("Cheep")
+	}
+}
+
+class Owl : Bird {
+	func talk() {
+		System.print("Hoot")
+	}
+}
+
+func main() {
+	var bird = Bird()
+	bird.talk() // Output: Cheep
+
+	var owl = Owl()
+	owl.talk() // Output: Hoot
+}
+```
+
 ### Access specifiers
 The public and private keywords can be used to restrict access to specific parts of code.