> For the complete documentation index, see [llms.txt](https://gyansetu-selenium.gitbook.io/selenium-testing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gyansetu-selenium.gitbook.io/selenium-testing/access-modifiers.md).

# Access Modifiers

&#x20;Access modifiers help you set the level of access you want for your Class, variables as well as Methods.

&#x20;The access modifiers in java specify accessibility (scope) of a data member, method, constructor or class.&#x20;

#### There are 4 types of java access modifiers:

&#x20;1\. Private

&#x20;2\. Default

&#x20;3\. Protected&#x20;

4\. public

#### &#x20;1) private access modifier&#x20;

The private access modifier is accessible only within class. Simple example of private access modifier In this example, we have created two classes A and Simple. A class contains private data member and private method. We are accessing these private members from outside the class, so there is compile time error.

![](/files/-LTfY79U9lkXu-TyeUhn)

#### &#x20;2) default access modifier

&#x20;If you don't use any modifier, it is treated as default by default. The default modifier is accessible only within package.

![](/files/-LTfYJNVY5Xs5uI0wKpN)

#### &#x20;3) protected access modifier

#### &#x20;The protected access modifier is accessible within package and outside the package but through inheritance only. **The protected access modifier can be applied on the data member, method and constructor. It can't be applied on the class.**

![](/files/-LTfYX_x02dA9TKRUeK1)

#### &#x20;4) public access modifier

&#x20;The public access modifier is accessible everywhere. It has the widest scope among all other modifiers.

![](/files/-LTfYgPQUnXdl5rNtXoF)

![](/files/-LTfYmHA_51NPpKUkyQl)

![](/files/-LTfYqL0uLHs-mCJoOXv)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gyansetu-selenium.gitbook.io/selenium-testing/access-modifiers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
