首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

如何让某个类不能使用某个方法

2012-03-22 
怎么让某个类不能使用某个方法?创建一个银行账户Account 类,有存款,取款等方法,在创建两个子类,其中有一个

怎么让某个类不能使用某个方法?
创建一个银行账户Account 类,有存款,取款等方法,在创建两个子类,其中有一个是SavingAccount,SavingAccount不能透支,所以能否使SavingAccount不访问取款方法?
代码如下(没写完):



package pkg;

public class test9_3 {
public void main(String[] args)
{
//SavingAcc saving = new SavingAcc();
}



public class Account
{
int accountNum= 0;
private double balance = 0;//yu e
private double yearInterest = 0;
private String openDate = null ;

Account(int accountNum , double balance , double yearInterest ,String openDate)
{
this.accountNum = accountNum;
this.balance = balance ;
this.yearInterest = yearInterest ;
this.openDate = openDate ;
System.out.print("this is Account class");
}

//Account(){}


public double getBanlance()
{
return balance;
}



public void deposit(double depositMoney)
{
balance += depositMoney ; 
}

public void drawMoney(double DMoney)
{
balance -=DMoney;
}
}
}






package pkg;

import pkg.test9_3.Account;

public class SavingAcc extends Account {

SavingAcc(test9_3 test9_3, int accountNum, double balance,double yearInterest, String openDate) {
test9_3.super(accountNum, balance, yearInterest, openDate);
// TODO Auto-generated constructor stub

if(this.getBanlance() < 0)
{
System.out.println("your Account's balance is lower than $0");
}
else
;
}
}

[解决办法]
SavingAccount 的 drawMoney 抛出 UnsupportedOperationException
[解决办法]

探讨
SavingAccount 的 drawMoney 抛出 UnsupportedOperationException

[解决办法]
探讨

SavingAccount 的 drawMoney 抛出 UnsupportedOperationException

热点排行
Bad Request.