static2 [면접질문대비] Static 클래스/메서드는 오버라이딩이 될까? NO! 1. 🔧 오버라이딩이란? 오버라이딩은 부모클래스의 메서드를 자식 클래스가 재정의하는 것 조건1. 인스턴스 메서드여야 함 ( static 안됨)2. 메서드 이름, 매개변수, 반환형이 같아야 함3. 접근 제어자는 더 좁게 하면 안 됨 2. ❗ static 메서드는 오버라이딩되지 않는다class Parent { static void sayHello() { System.out.println("Hello from Parent"); }}class Child extends Parent { static void sayHello() { System.out.println("Hello from Child"); }} Parent obj = new Child();obj.sayH.. 2025. 6. 6. [면접질문대비] Static 이란 무엇인가? 1. ✅ static 이란? Static 은 "정적인", 즉 클래스에 귀속되는 요소임을 나타내는 키워드자바에서 static이 붙은 변수나 메서드는 인스턴스(객체)가 없어도 사용 가능하며, 클래스 수준에서 공유 2. 🔍 static이 붙을 수 있는 대상대상의미변수 (static 변수)모든 객체가 공유하는 클래스 변수메서드 (static 메서드)인스턴스 없이 호출 가능한 클래스 메서드블록 (static 초기화 블록)클래스 로딩 시 단 한 번 실행클래스 (staitc 중첩 클래스)외부 클래스에 종속된 내부 정적 클래스 3. 📦 static 변수 (클래스 변수)public class User { public static int userCount = 0; public User() { u.. 2025. 6. 6. 이전 1 다음