❓
물음표살인마 블로그
  • README
  • ALGORITHM
    • Sieve of Eratosthenes
    • Round Up
    • Binary Search
    • Union Find
    • Sorting Array
    • Lcm, Gcd
  • TechTalk Review
    • Template
  • Books
    • CS Note for Interview
      • Ch1. Design Pattern & Programming paradigm
        • 1.1.1 Singleton Pattern
        • 1.1.2 Factory Pattern
        • 1.1.4 Observer Pattern
        • 1.1.5 Proxty Pattern & Proxy Server
        • 1.1.8 Model-View-Controller Pattern
        • 1.2.1 Declarative and Functional Programming
        • 1.2.2 Object Oriented Programming
      • Ch2. Network
        • 2.2.1 TCP/IP Four-Layer Model
        • 2.2.1-1 TCP 3, 4 way handshake
        • 2.3 Network Devices L4, L7
        • 2.4.1 ARP, RARP
        • 2.4.2 Hop By Hop Communication
        • 2.4.3 IP Addressing Scheme
      • Ch3. Operating System
        • 3.1.1 Roles and Structure of Operating Systems
        • 3.2.1 Memory Hierarchy
        • 3.2.2 Memory Management
        • 3.3.1 Processes and Compilation Process
        • 3.3.3 Memory Structure of a Process
        • 3.3.4 Process Control Block (PCB)
        • 3.3.5 Multiprocessing
        • 3.3.6 Threads and Multithreading
        • 3.3.7 Shared Resources and Critical Sections
        • 3.3.8 Deadlock
        • 3.4 CPU Scheduling Algorithm
      • Ch4. Database
        • 4.1 Database Basic
        • 4.2 Normalization
        • 4.3 Transaction and Integrity
        • 4.4 Types of Databases
        • 4.5 Indexes
        • 4.6 Types of Joins
        • 4.7 Principles of Joins
      • Ch5. Data Structure
    • Learning the Basics of Large-Scale System Design through Virtual Interview Cases
      • 1. Scalability based on user counts(1/2)
      • 1. Scalability based on user counts(2/2)
      • 2.Back-of-the-envelope estimation
      • 3. Strategies for System Design Interviews
      • 4. Rate Limiter
      • 5. Consistent Hashing
      • 6. Key-Value System Design
      • 7. Designing a Unique ID Generator for Distributed Systems
      • 8. Designing a URL Shortener
      • 9. Designing a Web Crawler
      • 10. Notification System Design
      • 11. Designing a News Feed System
      • 12. Chat System Design
      • 13. AutoComplete
      • 14. Design YouTube
      • 15. Design Google Drive
      • Loadbalancer Algorithms
      • Cache tier
      • CDN, Content Delivery Network
      • Stateless Web tier
    • Computer System A programmer's perspective
    • Effective Java
      • Item 1. Consider Static Factory Methods Instead of Constructors
      • Item 2. Consider a Builder When Faced with Many Constructor Parameters
      • Item 3. Ensure Singleton with Private Constructor or Enum Type
      • Item 4. Enforce Noninstantiability with a Private Constructor
      • Item 5. Prefer Dependency Injection to Hardwiring Resources
      • Item 6. Avoid Creating Unnecessary Objects
      • Item 7. Eliminate Obsolete Object References
      • Item 8. Avoid Finalizers and Cleaners
      • Item 9.Prefer try-with-resources to try-finally
      • Item10. Adhering to General Rules When Overriding equals
        • Handling Transitivity Issues
        • Ensuring Consistency
      • Item11. Override hashCode When You Override equals
      • Item12. Always Override toString
        • Always Override toString
      • Item13. Override Clone Judiciously
      • Item14. Consider Implementing Comparable
      • Item15. Minimize the Accessibility of Classes and Members
      • Item16. Accessor Methods Over Public Fields
      • Item17. Minimize Mutability
      • Item18. Composition over inherentance
      • Item19. Design and Document for Inheritance, or Else Prohibit It
      • Item20. Prefer Interfaces to Abstract Classes
      • Item21. Design Interfaces with Implementations in Mind
      • Item22. Use Interfaces Only to define Types
      • Item23. Prefer Class Hierarchies to Tagged Classes
      • Item24. Favor Static Member Classes Over Non-Static
      • Item28. Use Lists Instead of Arrays
      • Item29. Prefer Generic Types
      • Item30. Favor Generic Methods
    • Head First Design Patterns
      • Ch1. Strategy Pattern
      • Ch2. Observer Pattern
        • Ver1. Ch2. Observer Pattern
      • Ch3. Decorator Pattern
        • Ch3. Decorator Pattern
      • Ch4. Factory Pattern
      • Ch5. Singleton Pattern
      • Ch6. Command Pattern
      • Ch7. Adapter and Facade Pattern
      • Ch8. Template Method Pattern
    • Digging Deep into JVM
      • Chapter 2. Java Memory Area & Memory Overflow
      • Chapter 3. Garbage Collector & Memory Allocation Strategy (1/2)
      • Chapter 3. Garbage Collector & Memory Allocation Strategy (2/2)
      • Chapter 5. Optimization Practice
      • Chapter 6. Class file structure
      • Chapter 8. Bytecode Executor Engine (1/2)
  • Interview Practices
    • Restful API Practices
      • Url Shortener API
      • Event Ticket Reservation API
      • Course Management API
      • Search posts by tags API
      • Online Code platform API
      • Simple Task Management API
      • Event Participation API
      • Review System API
      • Car management API
      • Online Library
    • Tech Review
      • if(kakao)
        • Kakao Account Cache Migration / if(kakao)2022
        • Improving the Anomaly Detection System for KakaoTalk Messaging Metrics / if(kakao) 2022
        • Standardizing API Case Handling Without Redeployment / if(kakaoAI)2024
        • JVM warm up / if(kakao)2022
    • Naver Computer Science
      • Process & Thread
      • TCP & UDP
      • Spring & Servlet
      • Filter & Interceptor & AOP
      • Equals() & ==
      • Dependency Injection
      • Object Oriented Programming
  • F-Lab
    • Week1
      • Client & Server
      • HTTP
      • TCP/UDP
      • REST API
      • Questions
        • Object Oriented Programming
        • HTTP
        • Process & Thread
        • Data Structure
    • Week2
      • OSI 7 layer
      • Web vs WAS
    • Week3
      • RDB vs NoSQL
      • RDB Index
      • Cache
      • Redis
      • Messaging Queue
    • Week4
      • Project - Ecommerce
    • Week5
      • ERD - 1
    • Week6
      • Ecommerce - 2
      • Role
      • pw hashing && Salt
      • CreatedAt, ModifiedAt
      • JWT
      • Copy of ERD - 1
    • Week7
      • Vault (HashiCorp Vault)
    • Week 8
      • Api Endpoints
    • Week10
      • Product Create Workflow
  • TOY Project
    • CodeMentor
      • Implementation of Kafka
      • Project Improvement (Architectural Enhancements)
      • Communication between servers in msa
  • JAVA
    • MESI protocol in CAS
    • CAS (Compare and Set)
    • BlockingQueue
    • Producer & Consumer
    • Synchronized && ReentrantLock
    • Memory Visibility
    • Checked vs Unchecked Exception
    • Thread
    • Batch delete instead of Cascade
    • Java Questions
      • Week 1(1/2) - Basic Java
      • Week 1(2/2) - OOP
      • Week 2(1/2) - String, Exception, Generic
      • Week2(2/2) Lambda, Stream, Annotation, Reflection
      • Week3(1/2) Collections
      • Week3(2/2) Threads
      • Week4 Java Concurrency Programming
      • Week5 JVM & GC
    • Java 101
      • JVM Structure
      • Java Compiles and Execution Method
      • Override, Overload
      • Interface vs Abstract Class
      • Primitive vs Object Type
      • Identity and equality
      • String, StringBuilder, StringBuffer
      • Checked Exceptions and Unchecked Exceptions
      • Java 8 methods
      • Try-with-reources
      • Strong Coupling and Loose Coupling
      • Serialization and Deserialization
      • Concurrency Programming in Java
      • Mutable vs Immutable
      • JDK vs JRE
  • SPRING
    • DIP. Dependency Inversion Principal
    • Ioc container, di practice
    • @Transactional
    • Proxy Pattern
    • Strategy Pattern
    • Template Method Pattern
    • using profile name as variable
    • Spring Questions
      • Spring Framework
      • Spring MVC & Web Request
      • AOP (Aspect-Oriented Programming)
      • Spring Boot
      • ORM & Data Access
      • Security
      • ETC
  • DATABASE
    • Enhancing Query Performance & Stability - User list
    • Ensuring Data Consistency, Atomicity and UX Optimization (feat.Firebase)
    • Redis: Remote Dictionary Server
    • Database Questions
      • Week1 DBMS, RDBMS basics
      • Week2 SQL
      • Week3 Index
      • Week4 Anomaly, Functional Dependency, Normalization
      • Week5 DB Transaction, Recovery
    • Normalization
      • 1st Normal Form
      • 2nd Normal Form
      • 3rd Normal Form
  • NETWORK
    • HTTP & TCP head of line blocking
    • HTTP 0.9-3.0
    • Blocking, NonBlocking and Sync, Async
    • Network Questions
      • Week1 Computer Network Basic
      • Week2(1/3) Application Layer Protocol - HTTP
      • Week2(2/3) Application Layer Protocol - HTTPS
      • Week2(3/3) Application Layer Protocol - DNS
      • Week3 Application Layer
      • Week4 Transport Layer - UDP, TCP
      • Week5 Network Layer - IP Protocol
    • Network 101
      • https://www.google.com
      • TCP vs UDP
      • Http vs Https
      • TLS Handshake 1.2
      • HTTP Method
      • CORS & SOP
      • Web Server Software
  • OS
    • Operating System Questions
      • Week1 OS & How Computer Systems Work
      • Week2(1/2) Process
      • Week2(2/2) Thread
      • Week3 CPU Scheduling
      • Week4 Process Synchronize
      • Week5 Virtual Memory
    • Operating System 101
      • Operating system
        • The role of the operating system
        • The composition of the operating system.
      • Process
        • In Linux, are all processes except the initial process child processes?
        • Zombie process, orphan process
        • (Linux) Daemon process
        • Process address space
        • Where are uninitialized variables stored?
        • Determination of the size of the Stack and Heap
        • Access speed of Stack vs Heap
        • Reason for memory space partitioning
        • Process of compiling a process
        • sudo kill -9 $CURRENT_PID
      • Thread
        • Composition of a thread's address space
      • Process vs Thread
        • Creation of processes and threads in Linux
      • Multiprocessing
        • Web Browser
        • Implementation of multiprocessing
        • Application areas of multiprocessing
      • Multithreading
        • Application areas of multithreading
      • Interrupt
        • HW / SW Interrupt
        • Method of handling interrupts
        • Occurrence of two or more interrupts simultaneously
      • Polling
      • Dual Mode
        • Reason for distinguishing between user mode and kernel mode
      • System call
        • Differentiation between system calls
        • Types of system calls
        • Execution process of a system call
      • Process Control Block (PCB)
        • PCB의 구조
        • 쓰레드는 PCB를 갖고 있을까?
        • 프로세스 메모리 구조
      • Context switching
        • Timing of context switching
        • Registers saved during context switching
        • Context switching in processes
        • Context switching in threads
        • Difference between context switching in processes and threads
        • Information of the current process during context switching
      • Interprocess Communication (IPC)
        • Cases where IPC is used
        • Process address space in IPC Shared Memory technique
        • Types of IPC
  • COMPUTER SCIENCE
    • Computer Architecture 101
      • 3 components of a computer
      • RAM vs ROM
      • CPU vs GPU
      • SIMD
      • Two's complement
      • Harvard Architecture vs. von Neumann Architecture
      • The structure of a CPU.
      • Instruction cycle (CPU operation method)
      • Instruction pipelining
      • Bus
      • Memory area
      • Memory hierarchy structure
        • Reason for using memory hierarchy structure
      • Cache memory
      • L1, L2, L3 Cache
      • Locality of reference (cache)
      • Fixed-point vs Floating-point
        • epresentation of infinity and NaN (Not a Number) in floating-point
      • RISC vs CISC
      • Hamming code
      • Compiler
      • Linking
      • Compiler vs Interpreter
      • Mutex vs Semaphore
      • 32bit CPU and 64bit CPU
      • Local vs Static Variable
      • Page
  • Programming Paradigm
    • Declarative vs Imperative
  • JPA, QueryDsl
    • why fetchResults() is deprecated
  • PYTHON
    • Icecream
  • FASTAPI
    • Template Page
  • LINUX
    • Template Page
  • DATA STRUCTURE
    • Counting Sort
    • Array vs Linked List
  • GIT, Github
    • git clone, invalid path error
  • INFRA
    • Template Page
  • AWS
    • Server Log Archive Pipeline
    • Image Processing using Lambda
  • DOCKER
    • Docker and VM
    • Python Executable Environment
    • Docker commands
  • docker-compose
    • Kafka, Multi Broker
  • KUBERNATES
    • !Encountered Errors
      • my-sql restarts
      • kafka producer: disconnected
    • Kubernetes Components
    • Helm
      • Helm commands
    • Pod network
    • Service network
      • deployment.yaml
      • services.yaml
    • Service type
      • Cluster IP
      • NodePort
    • service-name-headless?
    • kube-proxy
  • GraphQL
    • Template Page
  • WEB
    • Template Page
  • Reviews
    • Graphic Intern Review
    • Kakao Brain Pathfinder Review
    • JSCODE 자바 1기 Review
  • 😁Dev Jokes
    • Image
      • Plot twist
      • Priorities
      • SQL join guide
      • Google is generous
      • Genie dislikes cloud
      • buggy bugs
      • last day of unpaid internship
      • what if clients know how to inspect
      • its just game
      • how i wrote my achievement on resume
      • self explanatory
      • chr(sum(range(ord(min(str(not))))))
Powered by GitBook
On this page
  1. JAVA
  2. Java Questions

Week 1(2/2) - OOP

자바 객체 지향

오버로딩과 오버라이딩의 차이는 뭔가요?

오버로딩은 같은 이름의 메서드를 여러 개 정의하는 것이며, 주로 메서드의 매개변수 목록(파라미터 리스트)을 다르게 설정하여 구현됩니다.

오버라이딩은 상속 관계에 있는 클래스에서 부모 클래스의 메서드를 재정의하는 것을 의미합니다.

다형성이 무엇이고, 왜 필요할까요?

같은 메서드나 연산자가 서로 다른 클래스에서 다양한 방식으로 동작할 수 있게 하는 능력을 의미합니다. 쉽게 말해, "하나의 인터페이스에 대해 여러 가지 형태의 구현이 가능하다"는 것을 뜻합니다.

  • 컴파일타임 다형성 (Compile-time Polymorphism) / 정적 다형성 (Static Polymorphism). 주로 메서드 오버로딩을 통해 구현됩니다.

  • 런타임 다형성 (Runtime Polymorphism) / 동적 다형성 (Dynamic Polymorphism). 주로 메서드 오버라이딩과 인터페이스를 통해 구현됩니다.

  • 유연성과 확장성 다형성은 코드의 유연성을 크게 높여줍니다. 예를 들어, 여러 종류의 객체가 동일한 인터페이스를 구현하거나 같은 부모 클래스를 상속받아 메서드를 오버라이딩하면, 특정 객체의 타입에 의존하지 않고 동일한 방식으로 메서드를 호출할 수 있습니다. 이를 통해 새로운 클래스나 기능을 추가할 때 기존 코드를 수정하지 않고도 확장할 수 있습니다.

  • 코드 재사용성: 다형성을 활용하면 공통된 인터페이스나 부모 클래스를 통해 코드의 재사용성을 높일 수 있습니다. 여러 클래스에서 동일한 메서드 시그니처를 사용하여, 다양한 객체가 동일한 방식으로 처리되도록 코드를 작성할 수 있습니다.

  • 유지보수의 용이성 다형성은 유지보수를 쉽게 해줍니다. 예를 들어, 새로운 타입이 추가되거나 기존 타입이 변경될 때, 공통 인터페이스나 부모 클래스의 메서드만 수정하면 됩니다. 이를 통해 코드의 수정 범위를 최소화할 수 있습니다.

상속은 무엇인가요?

기존의 클래스를 재사용하여 새로운 클래스를 만드는 방법입니다. 상속을 통해 새로운 클래스(자식 클래스 또는 서브클래스)는 기존 클래스(부모 클래스 또는 슈퍼클래스)의 필드(멤버 변수)와 메서드(멤버 함수)를 물려받을 수 있습니다. 상속을 통해 코드의 재사용성과 확장성을 높일 수 있으며, 상위 클래스에서 정의한 기능을 하위 클래스에서 재사용하거나 확장할 수 있습니다.

상속의 단점은 무엇이 있을까요?
  • 부모 클래스와 자식 클래스 간의 강한 결합

  • 설계의 복잡성 증가

상속과 조합의 차이에 대해 설명해 주세요.

상속은 부모 클래스(슈퍼클래스)의 속성과 동작(메서드)을 자식 클래스(서브클래스)에 물려주는 메커니즘입니다. 상속을 통해 자식 클래스는 부모 클래스의 모든 멤버(필드와 메서드)를 상속받아 사용할 수 있으며, 필요에 따라 부모 클래스의 메서드를 오버라이딩(Overriding)하여 새로운 동작을 정의할 수도 있습니다.

조합은 객체가 다른 객체를 자신의 멤버 변수로 포함하여 기능을 재사용하는 방식입니다. 조합을 사용하면 객체는 포함된 다른 객체의 기능을 사용하면서도 각 객체가 독립적으로 존재할 수 있습니다. 조합은 일반적으로 "has-a" 관계를 나타냅니다.

상속과 조합의 차이점

  • 관계:

    • 상속: "is-a" 관계를 나타냅니다. 자식 클래스는 부모 클래스의 일종이며, 부모 클래스의 특성을 상속받아 재사용합니다.

    • 조합: "has-a" 관계를 나타냅니다. 객체는 다른 객체를 포함하고 있으며, 이 포함된 객체의 기능을 사용합니다.

  • 재사용성:

    • 상속: 부모 클래스의 모든 멤버(필드와 메서드)를 자식 클래스가 상속받습니다. 이는 코드 재사용에 유리하지만, 부모 클래스에 의존적입니다.

    • 조합: 다른 객체를 포함하여 그 객체의 기능을 사용할 수 있습니다. 각 객체는 독립적으로 존재하며, 유연성이 높습니다.

  • 결합도:

    • 상속: 부모 클래스와 자식 클래스 간의 강한 결합(의존성)이 존재합니다. 부모 클래스의 변경이 자식 클래스에 영향을 미칠 수 있습니다.

    • 조합: 결합도가 낮고, 포함된 객체는 독립적으로 변경될 수 있습니다. 이는 유지보수와 확장성 측면에서 유리합니다.

  • 확장성:

    • 상속: 계층 구조가 깊어지면 클래스 간의 관계가 복잡해지고, 유지보수가 어려워질 수 있습니다.

    • 조합: 필요에 따라 객체 간의 관계를 쉽게 변경하거나 확장할 수 있습니다. 새로운 기능을 추가하기 위해 상속보다는 조합이 더 유연한 방법이 될 수 있습니다.

instanceof 키워드란 무엇인가요?

instanceof는 Java에서 사용되는 키워드로, 객체가 특정 클래스나 인터페이스의 인스턴스인지 여부를 검사하는 데 사용됩니다. 이 키워드는 주로 객체의 타입을 확인하거나, 안전하게 타입 캐스팅을 하기 전에 타입을 검증할 때 사용됩니다.

instanceof 키워드를 사용할 때 문제점으로 무엇이 있을까요?
  • 타입 종속성 증가

  • 다형성의 저해

  • 복잡한 논리와 가독성 저하

interface란 무엇일까요?

Java에서 클래스나 객체가 특정 기능을 수행하기 위해 반드시 구현해야 하는 메서드들의 집합을 정의한 것입니다. 인터페이스는 객체 지향 프로그래밍에서 다형성을 구현하는 중요한 도구로, 클래스가 어떤 동작을 수행할 수 있는지를 명시하지만, 그 동작의 구체적인 구현은 클래스에 맡깁니다.

interface와 abstract class는 어떤 차이가 있나요?

다중 상속 지원 여부

  • 인터페이스: Java에서는 클래스가 여러 인터페이스를 **구현(implements)**할 수 있습니다. 이를 통해 다중 상속을 우회적으로 지원하며, 다양한 기능을 한 클래스에 포함시킬 수 있습니다.

  • 추상 클래스: 클래스는 하나의 추상 클래스만 **상속(extends)**할 수 있습니다. 다중 상속은 허용되지 않으며, 이는 클래스 간의 관계를 단순화하고, 다중 상속으로 인한 모호성을 방지하기 위함입니다.

2. 메서드 구현 여부

  • 인터페이스: Java 8 이전의 인터페이스는 메서드의 시그니처만 선언할 수 있고, 메서드의 구현을 포함할 수 없었습니다. Java 8 이후로는 디폴트 메서드(default methods)와 정적 메서드(static methods)를 인터페이스에 포함할 수 있으며, 이들은 기본적인 구현을 가질 수 있습니다. 그러나 인터페이스의 메서드 구현은 제한적이며, 주요 목적은 구현을 강제하는 것입니다.

  • 추상 클래스: 추상 클래스는 추상 메서드뿐만 아니라, 일반 메서드(구현된 메서드)도 가질 수 있습니다. 이는 공통된 기능을 여러 서브클래스에서 공유하면서도, 특정 기능은 서브클래스에서 구현하도록 강제할 수 있습니다.

3. 필드(변수) 사용

  • 인터페이스: 인터페이스 내에서는 상수(public static final)만 선언할 수 있으며, 인스턴스 변수를 가질 수 없습니다. 모든 필드는 자동으로 public static final로 간주됩니다.

  • 추상 클래스: 추상 클래스는 인스턴스 변수(필드)를 가질 수 있습니다. 이를 통해 상태를 유지하거나 서브클래스에서 공유할 공통된 데이터를 정의할 수 있습니다.

4. 생성자

  • 인터페이스: 인터페이스에는 생성자가 없습니다. 인터페이스는 인스턴스화할 수 없으며, 인터페이스 자체로 객체를 만들 수 없습니다.

  • 추상 클래스: 추상 클래스는 생성자를 가질 수 있으며, 서브클래스에서 추상 클래스를 상속받을 때 해당 생성자를 호출할 수 있습니다. 추상 클래스는 인스턴스를 만들 수 없지만, 생성자는 서브클래스 초기화 시 사용할 수 있습니다.

5. 사용 목적

  • 인터페이스: 인터페이스는 주로 기능을 정의하는 데 사용됩니다. 클래스가 어떤 동작을 수행해야 하는지 명시하는 역할을 하며, 다양한 클래스에서 동일한 동작을 구현하도록 강제합니다. 인터페이스를 구현한 클래스들은 각기 다른 상속 계층에 속할 수 있으며, 특정 기능을 공통적으로 구현하게 됩니다.

  • 추상 클래스: 추상 클래스는 상속받는 클래스들 간의 공통된 특성을 정의하는 데 사용됩니다. 서브클래스 간의 공통된 속성이나 동작을 공유하고, 일부 동작만을 서브클래스에서 정의하도록 강제합니다.

6. 추상화 수준

  • 인터페이스: 인터페이스는 100% 추상화를 제공합니다. 모든 메서드는 기본적으로 추상적이며, 객체가 수행해야 하는 동작을 정의합니다.

  • 추상 클래스: 추상 클래스는 부분적인 추상화를 제공합니다. 일부 메서드는 구현이 되어 있을 수 있고, 일부 메서드는 서브클래스에서 구현하도록 강제할 수 있습니다.

언제 interface 사용하고, 언제 abstract class 사용 하나요?

인터페이스(interface)를 사용할 때

  1. 다중 상속이 필요할 때:

    Java에서는 클래스가 하나의 클래스만 상속받을 수 있지만, 여러 개의 인터페이스를 구현할 수 있습니다. 따라서 클래스가 여러 개의 기능을 가져야 하며, 이러한 기능들이 서로 관련이 없을 때 인터페이스를 사용합니다.

  1. 행동을 명시할 때: 인터페이스는 특정 클래스가 어떤 행동을 수행할 수 있는지를 정의합니다. 예를 들어, 여러 클래스가 공통적으로 수행해야 하는 행동이 있지만, 이 행동이 클래스의 계층 구조와 관련이 없을 때 인터페이스를 사용합니다.

  2. 클래스 간의 관련성이 없을 때 서로 관련이 없는 여러 클래스에 공통적인 행동을 정의하고 싶을 때 인터페이스를 사용합니다.

  3. 상수 필드가 아닌 필드를 포함하지 않을 때

추상 클래스(abstract class)를 사용할 때

  1. 클래스 간에 공통된 코드가 있을 때

  2. 기본 구현을 제공할 때 추상 클래스는 일부 메서드에 대해 기본 구현을 제공할 수 있습니다. 이를 통해 자식 클래스는 필요한 메서드만 오버라이딩하고, 나머지는 기본 구현을 사용할 수 있습니다.

  3. 상태(필드)를 가지는 공통 클래스를 만들고자 할 때 추상 클래스는 필드를 가질 수 있으므로, 자식 클래스 간에 공유될 공통 상태를 유지할 수 있습니다. 인터페이스는 상태를 가질 수 없으므로, 상태를 유지해야 한다면 추상 클래스를 사용해야 합니다.

  4. 상속 계층 구조에 속한 클래스를 만들고자 할 때 추상 클래스는 계층 구조를 통해 클래스 간의 상속 관계를 명확히 할 수 있습니다. 만약 클래스들이 서로 밀접하게 관련되어 있고, 공통된 특성을 물려받아야 한다면 추상 클래스를 사용합니다.

final 키워드에 대해 설명해 주세요.

final 키워드는 Java에서 변수, 메서드, 클래스에 사용할 수 있는 키워드로, 변경할 수 없는 상태를 명시적으로 표현하는 데 사용됩니다.

  • 변수에 사용: 변수는 초기화된 후 값을 변경할 수 없습니다.

  • 메서드에 사용: 오버라이딩 불가

  • 클래스에 사용: 클래스는 다른 클래스가 상속할 수 없습니다

PreviousWeek 1(1/2) - Basic JavaNextWeek 2(1/2) - String, Exception, Generic

Last updated 9 months ago