【Core java v1】ch4 OBJECTS AND CLASSES
2012-10-21 21:49
337 查看
Method Parameters
The Java programming language always uses call by value. That means that the method
gets a copy of all parameter values. In particular, the method cannot modify the con-
tents of any parameter variables that are passed to it.
There are, however, two kinds of method parameters:
• Primitive types (numbers, boolean values)
• Object references
You have seen that it is impossible for a method to change a primitive type parameter.
The situation is different for object parameters(The method gets a copy of the object reference, and both the original and the copy refer to the same object.) .
summary:
• A method cannot modify a parameter of primitive type (that is, numbers orboolean values).
• A method can change the state of an object parameter.
• A method cannot make an object parameter refer to a new object.
Object Construction
Here is what happens in detail when a constructor is called:
1. All data fields are initialized to their default value (0, false, or null).
2. All field initializers and initialization blocks are executed, in the order in which they occur in the class declaration.
3. If the first line of the constructor calls a second constructor, then the body of the second constructor is executed.
4. The body of the constructor is executed.
The Java programming language always uses call by value. That means that the method
gets a copy of all parameter values. In particular, the method cannot modify the con-
tents of any parameter variables that are passed to it.
There are, however, two kinds of method parameters:
• Primitive types (numbers, boolean values)
• Object references
You have seen that it is impossible for a method to change a primitive type parameter.
The situation is different for object parameters(The method gets a copy of the object reference, and both the original and the copy refer to the same object.) .
summary:
• A method cannot modify a parameter of primitive type (that is, numbers orboolean values).
• A method can change the state of an object parameter.
• A method cannot make an object parameter refer to a new object.
Object Construction
Here is what happens in detail when a constructor is called:
1. All data fields are initialized to their default value (0, false, or null).
2. All field initializers and initialization blocks are executed, in the order in which they occur in the class declaration.
3. If the first line of the constructor calls a second constructor, then the body of the second constructor is executed.
4. The body of the constructor is executed.
相关文章推荐
- Classes and Objects in PHP5(2)
- 第十一节--重载 -- Classes and Objects in PHP5 [11](转)
- 第七节--类的静态成员 -- Classes and Objects in PHP5 [7]
- Defining Classes and Objects
- 第四节--构造函数和析构函数 -- Classes and Objects in PHP5 [4
- A Swift Tour(4) - Objects and Classes
- Classes and Objects in PHP5(3)
- Think Python - Chapter 15 - Classes and objects
- Programming C#.Classes and Objects.只读字段
- 第十四节--命名空间 -- Classes and Objects in PHP5 [14](转)
- 第九节--绑定 -- Classes and Objects in PHP5 [9]
- 第二节--PHP5 的对象模型 -- Classes and Objects in PHP5 [2]
- thinkCSpy学习笔记: Chapter 13 Classes and objects 类和对象
- Classes and Objects in PHP5(4)
- 第十五节--Zend引擎的发展 -- Classes and Objects in PHP5 [15](转)
- 第十一节--重载 -- Classes and Objects in PHP5 [11]
- Classes and Objects
- 第五节--克隆 -- Classes and Objects in PHP5 [5]
- Reloading Java Classes 101: Objects, Classes and ClassLoaders Translation
- Java 基础 —— Objects and Classes