# Access to content of classes

\*\*\*\* **NOTE: BLOG MOVED TO** [**https://cmrodriguez.me/**](https://cmrodriguez.me/) **\*\*\*\***

Whenever we work with Java we have four scopes available applicable to a class, method or attribute. The following table shows what each scope means.

|             | Class | Package | Subclass (same pkg) | Subclass (diff pkg) | World |
| ----------- | ----- | ------- | ------------------- | ------------------- | ----- |
| public      | +     | +       | +                   | +                   | +     |
| protected   | +     | +       | +                   | +                   |       |
| no modifier | +     | +       | +                   |                     |       |
| private     | +     |         |                     |                     |       |

{% hint style="info" %}
\+ : accessible         blank : not accessible
{% endhint %}

As an example a private method can only be invoked by the class or instance that owns the method (if it is not static, just by an instance).

The static methods and objects can be used from a Frida script independently of the scope modifier, as shown in the following example:

```javascript
var ScopeObject = Java.use("com.blog.testfrida.complexobjects.ScopeObject");

console.log("private static object:" + ScopeObject.privateStaticObject.value);
console.log("protected static object:" + ScopeObject.protectedStaticObject.value);
console.log("public static object:" + ScopeObject.publicStaticObject.value);
console.log("static object:" + ScopeObject.nonModifiedStaticObject.value);

console.log("private static method:" + ScopeObject.privateStaticMethod());
console.log("protected static method:" + ScopeObject.protectedStaticMethod());
console.log("public static method:" + ScopeObject.publicStaticMethod());
console.log("static method:" + ScopeObject.nonModifiedStaticMethod());
```

In order to use the attributes and methods of an instance, we need to create an instance by calling its constructor. Frida acts like in the case of the static methods and attributes:

```javascript
var ScopeObject = Java.use("com.blog.testfrida.complexobjects.ScopeObject");
var scopeInstance = ScopeObject.$new();

console.log("private object:" + scopeInstance.privateObject.value);
console.log("protected object:" + scopeInstance.protectedObject.value);
console.log("public object:" + scopeInstance.publicObject.value);
console.log("object:" + scopeInstance.nonModifiedObject.value);

console.log("private method:" + scopeInstance.privateMethod());
console.log("protected method:" + scopeInstance.protectedMethod());
console.log("public method:" + scopeInstance.publicMethod());
console.log("method:" + scopeInstance.nonModifiedMethod());
```


---

# Agent Instructions: 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:

```
GET https://neo-geo2.gitbook.io/adventures-on-security/frida-scripting-guide/access-to-content-of-classes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
