Skip to content

Commit

Permalink
Merge pull request #11 from yuhan2680/main
Browse files Browse the repository at this point in the history
Translate more documents
  • Loading branch information
Alumopper authored Jul 2, 2024
2 parents fbee894 + fcb47dc commit 6984da7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 40 deletions.
38 changes: 19 additions & 19 deletions docs/en/quickstart/05class/02member.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
lastUpdate: true
---

# 类的成员
# Member of class

和Java类似,在MCFPP中,类的成员包括属性和方法。属性是类的数据成员,用来存储对象的数据;方法是类的函数成员,用来操作对象的数据。类的成员可以通过`.`操作符来访问。
Similar to Java, in MCFPP, members of class include attributes and methods. Attributes are the data members, used to store the data of the object; methods are the function of class member, used to operate the data of the object. Member of class can access by `.` operator.

## 属性
## Attributes

属性是类的数据成员,用来存储对象的数据。属性的定义语法如下:
Attributes are the data member of class, used to store the data of a object. The grammar to define attributes is shown below:

```mcfpp
class A{
Expand All @@ -17,11 +17,11 @@ class A{
}
```

上述代码定义了一个类`A`,它有两个属性`a``b``a`是一个整数类型的属性,没有初始化;`b`是一个整数类型的属性,初始化为`5`
The code before defined a class `A`, it has two attributes `a` and `b`. `a` is a integer attribute, not initialized; `b` is a integer attribute, initialized as `5`.

## 方法
## Method

方法是类的函数成员,用来操作对象的数据。方法的定义语法如下:
Methods are the function member of class, used to operate the data of the object. The grammar to define a method is shown below:

```mcfpp
class A{
Expand All @@ -31,7 +31,7 @@ class A{
}
```

在方法中使用`this`关键字可以访问对象的属性。例如:
Use keyword `this` can access the attributes of the object,such as:

```mcfpp
class A{
Expand All @@ -42,13 +42,13 @@ class A{
}
```

## 访问控制
## Access control

MCFPP中,类的成员可以使用`public``protected``private`关键字来控制访问权限。默认情况下,类的成员是`private`的。
In MCFPP, members of class can use keywords `public`, `protected` and `private` to control the access rights. Default, members of class are `private`.

- `public`公有的,可以被外部访问。
- `protected`受保护的,可以被子类访问。
- `private`私有的,只能在类的内部访问。
- `public`public, accessible to outside.
- `protected`protected, accessible to subclasses.
- `private`private, only can access in the class.

```mcfpp
class A{
Expand All @@ -59,16 +59,16 @@ class A{
class B: A{
void test(){
a = 1; #合法
b = 2; #合法
c = 3; #编译错误
a = 1; # Allowed
b = 2; # Allowed
c = 3; # Error
}
}
func test(){
A obj = new A();
obj.a = 1; #合法
obj.b = 2; #编译错误
obj.c = 3; #编译错误
obj.a = 1; # Allowed
obj.b = 2; # Error
obj.c = 3; # Error
}
```
16 changes: 8 additions & 8 deletions docs/en/quickstart/05class/03inheritance-abstract.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
lastUpdate: true
---

# 继承和抽象
# Inheritance and abstraction

MCFPP中,类支持继承和抽象。继承是指一个类可以派生出一个或多个子类,子类可以继承父类的属性和方法。抽象是指一个类可以定义抽象方法,子类必须实现这些抽象方法。
In MCFPP, class support supports Inheritance and abstraction. Inheritance means a class can derive one or many subclasses, subclasses can inherit parent class’s attributes and methods. Abstraction means a class can define abstract function, subclasses must achieve those abstract functions.

## 继承
## Inheritance

继承是指一个类可以派生出一个或多个子类,子类可以继承父类的属性和方法。继承的语法如下:
Inheritance means a class can derive one or many subclasses, subclasses can inherit parent class’s attributes and methods. The grammar of inheritance is shown below:

```mcfpp
class Parent{
Expand All @@ -28,11 +28,11 @@ class Child: Parent{
}
```

使用`:`关键字可以声明一个类继承自另一个类。利用`super`关键字,子类可以访问父类的属性和方法。使用`protected`关键字可以声明受保护的属性,子类可以访问父类的受保护属性。使用`override`关键字可以重写父类的方法。
Use keyword `:` can declare a class is inherited from another class. Use keyword `super`, subclasses can visit parent class’s attributes and methods. Keyword `protected` can declare the protected attributes, subclasses can visit the protected attributes of parent class. Use keyword `override` can rewrite parent class’s method.

## 抽象
## Abstraction

一个类可以定义抽象方法,子类必须实现这些抽象方法。抽象方法没有方法体,只有方法签名。抽象方法的定义语法如下:
A class can define abstract methods, subclasses must achieve those abstract methods. Abstract methods have no method body,only have method abstraction. The grammar to define a abstract method is shown below:

```mcfpp
abstract class A{
Expand All @@ -46,4 +46,4 @@ class B: A{
}
```

使用`abstract`关键字可以声明一个抽象类或一个抽象方法。抽象类的子类必须实现抽象方法,否则会编译错误。
Use keyword `abstract`can define an abstract class or an abstract method. The subclass of abstract class must achieve the abstract method, else there’ll be compilation error.
26 changes: 13 additions & 13 deletions docs/en/quickstart/06interface/01define-and-implement.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
lastUpdate: true
---

# 定义和实现接口
# Define and implement

MCFPP中,可以使用`interface`关键字来声明一个接口。接口是一种抽象的数据类型,它定义了一组方法的签名,但没有具体的实现。类可以实现一个或多个接口,从而保证类具有接口中定义的方法。
In MCFPP, can use keyword `interface` to declare an interface, interface is an abstract data type, it defines a group of function’s declaration, but have not achieved it. Class can achieve one or many interfaces, and make sure that class have the function defined in the interface.

## 接口的声明
## Define of interface

接口的声明语法如下:
The grammar to define a interface is shown below:

```mcfpp
interface InterfaceName{
Expand All @@ -18,27 +18,27 @@ interface InterfaceName{
}
```

接口中的方法只有方法签名,没有方法体。接口中的方法可以有多个,每个方法之间使用分号`;`分隔。接口中的方法一定都是抽象方法,但是不需要额外使用`abstract`关键字来声明
There’s only declaration in the function of the interface, no function body. A interface can have many functions, each function separate by `;`. Functions in interface must be abstract function, don’t need to use keyword `abstract` to declare.

## 接口的实现
## Achieve of interface

接口不能被实例化,但可以被类实现。
Interface can’t be instancing, but can achieve by class.

类可以实现一个或多个接口。实现接口的类必须实现接口中定义的所有方法。实现接口的语法如下:
Class can achieve one or many interfaces, the class that achieves interface must achieve all functions declared in the interface. The grammar of achieves a interface is shown below:

```mcfpp
class ClassName: Interface1, Interface2, ...{
#类的属性和方法
# Attributes and functions of class
...
override func methodName(parameterList) -> returnType{
#方法体
# Function body
}
}
```

## 接口的继承
## Inherit of interface

接口也可以继承自其他接口。继承接口的语法如下:
Interface also can inherit from other interfaces. The grammar of inherit a interface is shown:

```mcfpp
interface Interface1{
Expand All @@ -50,4 +50,4 @@ interface Interface2: Interface1{
}
```

如果一个类实现了一个继承了其他接口的接口,那么这个类必须实现接口以及其继承接口中定义的全部方法。
If a class achieve an interface that inherits from other interface, then the class must achieve all functions of the interface and its inherited interface.

0 comments on commit 6984da7

Please sign in to comment.