# On private keyword

**URL:** <https://discourse.processing.org/t/on-private-keyword/15139>\
**Category:** Beginners\
**Created:** [November 2, 2019, 5:39am UTC](https://discourse.processing.org/t/on-private-keyword/15139 "2019-11-02T05:39:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![plux](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@plux](https://discourse.processing.org/u/plux)\
**Post date:** [November 2, 2019, 5:39am UTC](https://discourse.processing.org/t/on-private-keyword/15139/1 "2019-11-02T05:39:48Z")

</div>

Hello,  
maybe I’m getting confused but I was expecting for this print line to return an error since I’m trying to access a private field (age) from outside its class (Parent)? Thanks

```auto

class Parent{
  private int age;
  
  public Parent(int age){
    this.age = age;
  }
}

class Child extends Parent{
  private String name;
  
  public Child(String name, int age){
    super(age);
    this.name = name;
  }
}

void setup(){
  Child c = new Child("Tom", 4);
  Parent p = new Parent(40);
  println("C: " + c.name + " - " + p.age); //I was expecting p.age to not work
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 2, 2019, 9:09am UTC](https://discourse.processing.org/t/on-private-keyword/15139/2 "2019-11-02T09:09:11Z")

</div>

> [@plux](#):
>
> … I’m trying to access a `private` field _age_ from outside its class Parent?

> **[private / Reference](https://processing.org/reference/private.html)**
>
> This keyword is used to disallow other classes access to the fields and methods within a class. The private keyword is used before a field or method that you want to be available only within th…

- All members inside “.pde” files belong to (are nested inside) a single PApplet subclass! 😮
- Nothing is actually `private` among them. 🕵️‍♂️
- However, access restriction would still apply when an access attempt is made from within a “.java” file to a “.pde” 1; and vice-versa. ⛔

---

<div class="post-metadata">

**Author:** ![plux](https://avatars.discourse-cdn.com/v4/letter/p/91b2a8/32.png) [@plux](https://discourse.processing.org/u/plux)\
**Post date:** [November 2, 2019, 9:21am UTC](https://discourse.processing.org/t/on-private-keyword/15139/3 "2019-11-02T09:21:10Z")

</div>

I see, thanks! I think the reference page is misleading since it says " In Processing, all fields and methods are public unless otherwise specified by the **private** keyword.".

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 2, 2019, 9:24am UTC](https://discourse.processing.org/t/on-private-keyword/15139/4 "2019-11-02T09:24:38Z")

</div>

Processing’s IDE (PDE) has a preprocessor that, among many other things, prefixes all methods w/ the keyword `public` if they don’t have 1 already on “.pde” files. 😳
