3.1.2 方法、参数和返回值



Methods in Java determine the messages an object can receive.
returnType methodName( /* argument list */ ) {
}
Java中的方法只能作为类的一部分创建。

调用一个对象的某方法时,先列出对象的名字,在一个period (dot)后跟上方法的名字和参数表,就象这样:

int x = a.f();
a的返回类型必须和x的类型符合。

This act of calling a method is commonly referred to as sending a message to an object.


Next Page