1. 程式人生 > >用面向物件的思想寫一個計算器

用面向物件的思想寫一個計算器

public class Calculate {
private int num1;
private int num2;
public int getNum1() {
return num1;
}
public void setNum1(int num1) {
this.num1 = num1;
}
public int getNum2() {
return num2;
}
public void setNum2(int num2) {
this.num2 = num2;
}

public void add(int num1,int num2){
System.out.println(num1+num2);
}
}

public class CalculateTest {
public static void main(String[] args) {
Calculate cc=new Calculate();
cc.add(20, 30);
}
}