static 개념정리2
package com.java1.day10;
class MyMath2 {
long a, b;
static int c;
long add() { return a + b; }
long subtract() { return a - b; }
long multiply() { return a * b; }
double divide() { return a / b; }
static long add(long a, long b) { return a + b; }
static long subtract(long a, long b) { return a - b; }
static long multiply(long a, long b) { return a * b; }
static double divide(double a, double b) { return a / b; }
}
public class MyMathTestEx08 {
public static void main(String[] args) {
System.out.println(MyMath2.c);
System.out.println(MyMath2.add(200L, 100L));
System.out.println(MyMath2.subtract(200L, 100L));
System.out.println(MyMath2.multiply(200L, 100L));
System.out.println(MyMath2.divide(200.0, 100.0));
System.out.println("--------------");
MyMath2 mm = new MyMath2();
mm.a = 200L;
mm.b = 100L;
mm.c = 200;
System.out.println(mm.c);
System.out.println(MyMath2.c);
System.out.println(mm.add());
System.out.println(mm.subtract());
System.out.println(mm.multiply());
System.out.println(mm.divide());
}
}
출력결과
0
300
100
20000
2.0
--------------
200
200
300
100
20000
2.0