AP计算机A自学笔记:方法类型

本文介绍了Java中构造函数的两种类型:默认构造函数和带有参数的构造函数,以及访问器(accessors)和存取器(mutators)的概念。通过一个银行账户类的例子,详细展示了如何定义和使用这些方法,并提供了相关方法的调用示例。
摘要由CSDN通过智能技术生成
  1. constructor 构造函数
    构造函数创建该类的一个对象,constructor无返回值
    constructor分两类:
    1 default constructor:
    不传入参数,使用默认值
    2 constructors with parameters:
    创建新对象时传入参数
  2. accessors 访问器
    访问一个对象,有返回值
  3. 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;
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值