ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 20200414
    언어/JAVA 2020. 4. 25. 00:32
    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
    package com.test;
    class A {
        void aMethod() { System.out.println("aMethod"); }
    class B extends A {
        void bMethod() { System.out.println("bMethod"); }
    }
    public class Test1 {
        public static void main(String[] args) {
            B b = new B();
            String className = b.getClass().getSimpleName();
            System.out.println(className);
            if(className.equals("B")) {
                System.out.println("B O.k");
            }
            if(b instanceof B) {
                System.out.println("B O.k2");
            }
            boolean check1 = b instanceof A;
            System.out.println(check1);
            B b1 = null;
            boolean check2 = b1 instanceof A;
            System.out.println(check2);
            
        }
    }
    ///////////////////////////////////////////////////////////
    package com.test;
    class Animal {
        void breath() {System.out.println("Animal breath");}    
    }
    class Dog extends Animal {
        void bark() {System.out.println("Bark breath");}
    }
    public class Test2 {
        public static void main(String[] args) {
            
            Dog d = new Dog();    
            Animal a = new Animal();
            test(d);
            test(a);
        }
        static void test(Animal a) {
            if(a instanceof Dog) {
                System.out.println("Dog");
            }
            else if(a instanceof Animal) {
                System.out.println("Animal");
            }
        }
    }
    ///////////////////////////////////////////////////////////
    package com.test;
    class MyClass {
        String m;
        void mMethod() {}
    }
    public class Test3 {
        public static void main(String[] args) {
            int[] arr;
            arr = new int[3];        
            int[] arr2 = new int[3];
            arr2[0= 1;
            arr2[1= 2;
            arr2[2= 3;
            
            for(int inx = 0; inx < arr2.length; inx++) {
                System.out.println(arr2[inx]);
            }
            
            MyClass[] arr3;
            arr3 = new MyClass[3];
            arr3[0= new MyClass();
            arr3[1= new MyClass();
            arr3[2]    = new MyClass();
            arr3[0].m = "홍길동";
            System.out.println(arr3[0].m);
        }
    }
     
    ///////////////////////////////////////////////////////////
     
    package com.test;
    class Box extends Object {
        String name;
        public Box(String name) {
            this.name = name;
        }
        public String toString() {
            return this.name;
        }
    }
    public class Test4 {
        static void println2(Object o) {
            System.out.println(o.toString());
        }
        public static void main(String[] args) {
            Box[] arrBoxes = new Box[2];
            arrBoxes[0= new Box("빨간색");
            arrBoxes[1= new Box("하얀색");
            System.out.println(arrBoxes[0]);
            System.out.println(arrBoxes[1]);
            println2(arrBoxes[0]);
            println2(arrBoxes[1]);
        
            
            
        }
    }
    ///////////////////////////////////////////////////////////
    package com.test;
    public class Test5 {
        public static void main(String[] args) {
            int[] arr = new int[3];
            arr[0= 1;
            arr[1= 2;
            arr[2= 3;
            for(int inx = 0; inx < arr.length; inx++) {
                System.out.println(arr[inx]);
            }
            for(int a : arr) {
                System.out.println(a);
            }
            String[] strs = {"이순신""홍길동""강감찬"};
            for(String nm : strs) {
                System.out.println(nm);
            }
            
     
        }
     
    }
     
     
    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' 카테고리의 다른 글

    20200416-2  (0) 2020.04.25
    20200416-1  (0) 2020.04.25
    20200413-2  (0) 2020.04.25
    20200413-1  (0) 2020.04.25
    접근지정자  (0) 2020.04.25
Designed by Tistory.