๋ชธํ๊ธฐ์ฉ ๋ฌธ์
๋ค์ ์ฝ๋์ ๊ฒฐ๊ณผ๊ฐ์ด ์ด๋ป๊ฒ ๋ ๊น์? ๊ทธ ์ด์ ๋?
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 ๋ฉ์๋๋ฅผ ์์ฑํ๋ฉด ์ด๋ป๊ฒ ๋ ๊น?
๋ค์ ์ฝ๋์ ๊ฒฐ๊ณผ๊ฐ ์ด๋ป๊ฒ ๋ ๊น์?
// 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();
}
}