class BankAccout
{
private double balance;
public BankAccout(double open) {
balance = open;
}
public void deposit(double amount){
balance+=amount;
}
public void display(){
System.out.println(balance);
}
}
class BankApp{
public static void main(String[] args) {
BankAccout ba1 = new BankAccout(1000);
ba1.deposit(10);
ba1.display();
}
}
将文件保存到d:test目录下的bank.java文件。(注意,这里的class没有public)。运行时:
javac bank.java
然后test目录出现两个class文件
接着
java BankApp,就会有结果1010.0