1: class Shape{
2: int x = 10;
3: double pai = 3.14;
4:
5: double square(int height,int width){
6: return height*width;
7: }
8:
9: void cube(){
10: int y = x*x*x;
11: System.out.println("立方体 cube = " + y);
12: }
13:
14: }
15:
16: class Kazu{
17: int a = 0;
18: int b = 0;
19: int c = 0;
20:
21: void disply(){
22: System.out.println("before");
23: System.out.println("a = " + a);
24: System.out.println("b = " + b);
25: System.out.println("c = " + c);
26: int b = 10;
27: int c = 20;
28: System.out.println("after");
29: System.out.println("a = " + a);
30: System.out.println("b = " + b);
31: System.out.println("c = " + c);
32: }
33:
34: void disply2(){
35: System.out.println("同じクラスで違うメソッド");
36: System.out.println("a = " + a);
37: System.out.println("b = " + b);
38: System.out.println("c = " + c);
39: }
40: }
41:public class Repo5test05{
42: public static void main(String[] args) {
43: double area;
44: Shape object;
45: object = new Shape();
46: area = object.square(10,20);
47:
48: System.out.println("四角形 square = " + area);
49:
50: object.cube();
51: object.x = 5;
52: object.cube();
53:
54: Kazu object2 = new Kazu();
55: object2.disply();
56: object2.disply2();
57: }
58:}
|