Skip to content

Latest commit

ย 

History

History
52 lines (39 loc) ยท 976 Bytes

File metadata and controls

52 lines (39 loc) ยท 976 Bytes

Java Basics

๋ชธํ’€๊ธฐ์šฉ ๋ฌธ์ œ

String ๋น„๊ต

๋‹ค์Œ ์ฝ”๋“œ์˜ ๊ฒฐ๊ณผ๊ฐ’์ด ์–ด๋–ป๊ฒŒ ๋ ๊นŒ์š”? ๊ทธ ์ด์œ ๋Š”?

String s1 = "hello";
String s2 = new String("hello");
String s3 = "hello";
String s4 = new String("hello");

System.out.println(s1 == s2);
System.out.println(s1 == s3);
System.out.println(s2 == s4);

static ํ•จ์ˆ˜๋Š” overrideํ•  ์ˆ˜ ์žˆ์„๊นŒ?

  • ๊ฐ€๋Šฅ/๋ถˆ๊ฐ€๋Šฅ?
  • ๊ทธ ์ด์œ ๋Š”?

๊ทธ๋ ‡๋‹ค๋ฉด ์ž์‹ ํด๋ž˜์Šค์—์„œ ๋™์ผํ•œ ์ด๋ฆ„์˜ static ๋ฉ”์†Œ๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด ์–ด๋–ป๊ฒŒ ๋ ๊นŒ?

๋‹ค์Œ ์ฝ”๋“œ์˜ ๊ฒฐ๊ณผ๊ฐ€ ์–ด๋–ป๊ฒŒ ๋ ๊นŒ์š”?

// Parent.java
class Parent {
    static void show() {
        System.out.println("Parent static show()");
    }
}

// Child.java
class Child extends Parent {
    static void show() {
        System.out.println("Child static show()");
    }
}

// Main.java
public class Main {
    public static void main(String[] args) {
        Parent obj = new Child();
        obj.show();
    }
}