8000 상속 · Issue #12 · daadaadaah/my-java · GitHub
[go: up one dir, main page]

Skip to content

상속 #12

Open
Open

Description

@daadaadaah

상속이란?

상속을 하는 이유?

protected 접근제어자가 필요한 이유

The protected access modifier in Java is used to provide a level of access control between classes within the same package and classes in subclasses. The protected modifier allows a subclass to access the members (fields and methods) of its superclass that are marked as protected, while still maintaining some level of access restriction compared to the public modifier.

Here are some reasons why the protected access modifier is necessary in Java:

Encapsulation: The protected modifier allows you to maintain the integrity of the class by hiding its internal details from other classes in the same package, while still allowing subclasses to access the necessary parts of the superclass. This helps to maintain the encapsulation of the class and reduces the risk of unintended side effects from other code.

Reusability: The protected modifier allows you to create reusable code by creating a class hierarchy. By making members protected, you can ensure that subclasses can access and extend the functionality of the superclass, while still maintaining encapsulation.

Polymorphism: The protected modifier allows you to use polymorphism in your code by creating a hierarchy of classes that share a common interface. Polymorphism allows you to write generic code that can handle objects of different classes in a type-safe manner.

In summary, the protected access modifier provides a balance between access control and code reuse, making it a valuable tool for creating robust, maintainable, and reusable Java code.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0