0
点赞
收藏
分享

微信扫一扫

Java 基础 —— 域


在看《Java编程思想》 P172 的时候遇到了一句话——“接口也可以包含域,但是这些域隐式地是 static 和 final 的。”

不知道 域 是啥玩意,于是查了一下。

http://www.answers.com/Q/What_is_a_field_in_java

What is a field in java?

A field is an attribute. A field may be a class’s variable, an object’s variable, an object’s method’s variable, or a parameter of a function.

field 域,是一种属性,可以是一个类变量,一个对象变量,一个对象方法变量或者是一个函数的参数。(补充,class‘s variables,类的实例变量和静态变量称为class’s variables,类属变量,也称类变量或数据域)。

class bike{   
  static int bikes;  
  int gear;  
  int cadence;  

  void create( int newGear, int newCadence ){  
    bikes = bikes + 1;  
    gear = newGear;  
    cadence = newCadence;}  
  int getSpeed(){  
    int speed = gear*cadence*5*3.141;  
    return speed;  
  }  
}

‘bikes’ is a class’s variable (class variable) (static field).
‘gear’ and ‘cadence’ could be an object’s variables (instance variables) (non-static fields).
‘speed’ is an object’s method’s variable (local variable).
‘newGear’ and ‘newCadence’ are parameters of a function (parameters).

bikes 是一个类变量。(静态域)
gearcadence 是对象的变量。(实例变量)(非静态域)
speed 是对象方法的变量。(局部变量)
newGearnewCadence 是方法的参数。(参数)

举报

相关推荐

0 条评论