ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 20200413-1
    언어/JAVA 2020. 4. 25. 00:23
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    package com.test;
    class Dog {
        public Dog() {
            age = 1;
            color = "Black";
            System.out.println("Default Constructor Dog");
        }
        public Dog(int ag, String clr) {
            age = ag;
            color = clr;
        }
        String breed;
        int age;
        String color;
        void barking() {}
        int hungry() { int a = 1int b = 2int c = a + b; return c;}
        void steeping() {}    
    }
    public class Test1 {
        public static void main(String[] args) {
            //Dog d = new Dog();
            Dog d2 = new Dog(2"땡칠이");
            int s = d2.hungry();    
        }
    }
    /////////////////////////////////////////////////////////
    package com.test;
     
    public class Test2 {
     
        public static void main(String[] args) {
            String str = new String("test");
            String str1 = new String("test");
            String str2 = "test";
            String str3 = "test";
            if(str == str1) {
                System.out.println("Ok");
            }
            if(str.equals(str1)) {
                System.out.println("Ok2");
            }
            if(str2 == str3) {
                System.out.println("Ok3");
            }
     
        }
     
    }
    /////////////////////////////////////////////////////////
    package com.test;
     
    class Calculator {
        int result;
        public Calculator() {
            result = 0;
        }
        public Calculator(int r) {
            result = r;
        }
        int add(int a, int b) {
            result = a + b;
            return result;
        }
        int subtract(int a, int b) {
            result = a - b;
            return result;
        }
        // Method Overloding
        int add(int a, int b, int c) {
            result = a + b + c;
            return result;
        }
    }
    public class Test3 {
        public static void main(String[] args) {
            //Calculator calc = new Calculator();
            Calculator calc = new Calculator(100);
            int a = 1;
            int b = 2;
            int result = calc.add(a, b);
            System.out.println(result);        
            
        }
     
    }
    /////////////////////////////////////////////////////////
    package com.test;
    class Student {
        public void gotoSchool() {
            System.out.println("Student go to school");
        }
        public void study() {
            System.out.println("Student study");
        }
    }
    class MiddleStudent extends Student {
        public void study2() {
            System.out.println("MiddleStudent study");
        }
    }
    public class Test4 {
        public static void main(String[] args) {
            MiddleStudent stu = new MiddleStudent();
            stu.gotoSchool();
            stu.study();
            stu.study2();
        }
    }
    /////////////////////////////////////////////////////////
    package com.test;
     
    class Student2 {
        String name;
        int age;
        public void setName(String name) {
            this.name = name;
        }
        public void setAge(int age) {
            this.age = age;
        }
    }
    public class Test5 {
        public static void main(String[] args) {
            Student2 stu = new Student2();
            stu.setName("홍길동");
            stu.setAge(30);
     
        }
     
    }
     
    /////////////////////////////////////////////////////////
    package com.test;
    class A {
        int aValue;
        public A() {
            System.out.println("Default Constructor A");
            this.aValue = 10;
        }
        public A(int aValue) {
            System.out.println("Constructor A");
            this.aValue = aValue;
        }
    }
     
    class B extends A {
        int bValue;
        public B() {
            System.out.println("Default Constructor B");
            this.bValue = 100;
        }
        public B(int bValue) {
            super(bValue);
            this.bValue = bValue;
            System.out.println("Constructor B " + bValue + ", " + this.aValue);
        }
    }
    public class Test6 {
        public static void main(String[] args) {
            B b = new B(100);
        }
    }
     
    /////////////////////////////////////////////////////////
    package com.test;
    class Student4 {
        String name;
        public Student4(String name) {
            this.name = name;
        }
    class MiddleStudent4 extends Student4 {
        int age;
        public MiddleStudent4(String name, int age) {        
            super(name);        
            //this.name = name;
            this.age = age;
            System.out.println(name + ", " + age);
        }    
    }
    public class Test7 {
        public static void main(String[] args) {
            MiddleStudent4 stu = 
                    new MiddleStudent4("홍길동"20);
     
        }
     
    }
     
    /////////////////////////////////////////////////////////
    package com.test;
    class MyClass{
        //int count;
        static int count;
        public MyClass() {
            count++;
            System.out.println(count);
        }
    }
    public class Test8 {
        public static void main(String[] args) {
            MyClass myClass = new MyClass();
            MyClass myClass2 = new MyClass();
            MyClass myClass3 = new MyClass();
            MyClass.count = 100;
            myClass.count = 200;
        }
     
    }
    /////////////////////////////////////////////////////////
    package com.test;
    class MyClass3 {
        int a;
        static int b;
        public static void setAValue(int x) {
            b = x;
        }
        public void setBValue(int y) {
            a = y;        
            setAValue(10);
        }    
    }
    public class Test9 {
        public static void main(String[] args) {
            MyClass3.b = 20;
            MyClass3 m = new MyClass3();
            m.a = 10;
            m.b = 20;
                    
     
        }
    }
    /////////////////////////////////////////////////////////
    package com.test;
    class MyClass4 {
        static int a;
        static int b;
        static {
            a = 1;
            b = 2;        
            System.out.println("Static Initialize");
        }    
    }
    public class Test10 {
        public static void main(String[] args) {
            MyClass4 m = new MyClass4();
     
        }
    }
    /////////////////////////////////////////////////////////
    package com.test;
    class Student5 {
        String name;
        int age;
        public Student5(String name, int age) {
            this.name = name;
            this.age = age;
        }
    }
    class HighStudent5 extends Student5 {
        int grade;
        public HighStudent5(String name, int age, int grade) {
            super(name, age);
            this.grade = grade;
        }
        void setNameAge(String name, int age) {
            this.name = name;
            this.age = age;
        }
        void study() {
            System.out.println(name + ", " + age + ", " + grade);
        }    
    }
    public class Test11 {
        public static void main(String[] args) {
            HighStudent5 stu = new HighStudent5("홍길동"201);
            stu.study();
            
     
        }
    }
     
    /////////////////////////////////////////////////////////
    package com.test;
    class A2 {
        void aMethod() {System.out.println("aMethod");}
    }
    class B2 extends A2 {
        void bMethod() {System.out.println("bMethod");}
        void aMethod() {System.out.println("aMethod on B2 Class");}
    }
    class C2 extends A2 {
        void cMethod() {System.out.println("cMethod");}
        void aMethod() {System.out.println("aMethod on C2 Class");}
    }
    public class Test12 {
        static void callMethod(B2 b) {
            b.aMethod();
        }
        static void callMethod(C2 c) {
            c.aMethod();
        }
        static void callMethod2(A2 a) {
            a.aMethod();
        }
        public static void main(String[] args) {
            callMethod(new B2());
            callMethod(new C2());
            callMethod2(new B2());
            callMethod2(new C2());
    //        B2 b = new B2();
    //        b.aMethod();
    //        b.bMethod();
    //        A2 a = b;
    //        a.aMethod();
    //        B2 b1 = (B2)a;
    //        b1.aMethod();
    //        b1.bMethod();
    //        
    //        C2 c = new C2();
    //        c.aMethod();
    //        c.cMethod();
    //        A2 a2 = c;
    //        a2.aMethod();
    //        C2 c2 = (C2)a2;
    //        c2.aMethod();
    //        c2.cMethod();
            
            B2 b2 = new B2();
            A2 a2 = b2;
            a2.aMethod();
     
     
        }
    }
    /////////////////////////////////////////////////////////
    package com.test;
    class Animal2 {
        void move() { System.out.println("Animal move");}
    }
    class Dog2 extends Animal2 {
        void move() { System.out.println("Dog move");}
    }
    class Cat2 extends Animal2 {
        void move() { System.out.println("Cat move");}
    }
    public class Test13 {
        static void goMove(Animal2 a) {
            a.move();
        }
        public static void main(String[] args) {
            Animal2 a = new Animal2();
            a.move();
            Dog2 d = new Dog2();
            d.move();
            Animal2 a2 = new Dog2();
            a2.move();
     
        }
     
    }
     
     
     
     
    http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
    http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

    '언어 > JAVA' 카테고리의 다른 글

    20200414  (0) 2020.04.25
    20200413-2  (0) 2020.04.25
    접근지정자  (0) 2020.04.25
    20200410  (0) 2020.04.25
    상속예제  (0) 2020.04.25
Designed by Tistory.