- constructor 构造函数
构造函数创建该类的一个对象,constructor无返回值
constructor分两类:
1 default constructor:
不传入参数,使用默认值
2 constructors with parameters:
创建新对象时传入参数 - accessors 访问器
访问一个对象,有返回值 - mutators 存取器
改变一个对象,如改变该对象一个变量值
package aPComputerScience;
public class BankAccount {
//this is an example of class
//static variables contain values that are shared by all instances of the class
//static variables are initialized outside the constructor
private String password;
private double balance;
//static final variables cannot change values
public static final double OVERDRAWN_PENALITY = 20.00;
//constructors
/*A constructor creates an object of the class
*A constructor has no return type
*/
/**Default constructor
* Constructs a bank account with default values
* @return
*/
public BankAccount() {
password = "";
balance = 0.00;