package Test22
//银行账户
class BankAccount(private[this] var balance:Int){
def showMoney():Unit={
println(s"现在的余额是:${balance}")
}
def deposit(money:Int):Unit={
balance+=money
}
def withdraw(money:Int):Unit= {
if (money <= balance)
balance -= money
}
//转账
def transfer(to:BankAccount,money:Int):Unit={
//A--200-->B
//A减少 B 增加
}
}
object Test22_2 {
def main(args: Array[String]): Unit = {
var xiaohua=new BankAccount(100)
//存入200
xiaohua.deposit(200)
//存入1500
xiaohua.withdraw(1500)
//转账给小明
xiaohua.showMoney()
// println(xiaohua.balance)
}
}
package Test22
//银行账户
class BankAccount(private var balance:Int){
def showMoney():Unit={
println(s"现在的余额是:${balance}")
}
def deposit(money:Int):Unit={
balance+=money
}
def withdraw(money:Int):Unit= {
if (money <= balance)
balance -= money
}
//转账
// def transfer(to:BankAccount,money:Int):Unit={
// //A--200-->B
//A减少 B 增加
// }
}
object Test22_2 {
def main(args: Array[String]): Unit = {
var xiaohua=new BankAccount(100)
//存入200
xiaohua.deposit(200)
//存入1500
xiaohua.withdraw(1500)
//转账给小明
xiaohua.showMoney()
// println(xiaohua.balance)
}
}
//private[p1]:表示,这方法在p1这个包中。是可以访问的
package p2 {
class C() {
private[p2] def test(): Unit = {
println("test")
}
}
object Test22_4 {
def main(args: Array[String]): Unit = {
var c1 = new C()
c1.test()
}
}
}