title: Why can I access a private fun outside a companion object in Kotlin?
body: <p>In my mind, a private function can only be accessed inside a class, but in my example the following code <code>bindPreferenceSummaryToValue(findPreference("RestoreItem"))</code>, which is outside the companion object, is accessible. Why?</p>
  
  <p><strong>Code</strong> </p>
  
  <pre><code>class UIPreference : AppCompatPreferenceActivity() {
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.layout_preference)
  
          fragmentManager.beginTransaction().replace(R.id.content, MyPreferenceFragment()).commit()
  
          setControl()
          utility.setAD(adView)
      }
  
  
      class MyPreferenceFragment : PreferenceFragment() {
  
          private lateinit var mContext: Context
  
          override fun onCreate(savedInstanceState: Bundle?) {
              super.onCreate(savedInstanceState)
              addPreferencesFromResource(R.xml.mypreference)
              mContext=this.activity
              setPreference()
  
              bindPreferenceSummaryToValue(findPreference("RestoreItem"))
          }
       }
  
  
       companion object {
          private val sBindPreferenceSummaryToValueListener = Preference.OnPreferenceChangeListener { preference, value -&gt;
              val stringValue = value.toString()
              if (preference is ListPreference) {
                  val listPreference = preference
                  val index = listPreference.findIndexOfValue(stringValue)
  
                  preference.setSummary(
                          if (index &gt;= 0)
                              listPreference.entries[index]
                          else
                              preference.summary)
  
              }
              true
          }
  
          private fun bindPreferenceSummaryToValue(preference: Preference) {           
              preference.onPreferenceChangeListener = sBindPreferenceSummaryToValueListener
  
              sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
                      PreferenceManager
                              .getDefaultSharedPreferences(preference.context)
                              .getString(preference.key, ""))
          }
      }
  
  
  }
  </code></pre>
  
  <p><strong>To David Rawson</strong></p>
  
  <p>Thanks! But from <a href="https://kotlinlang.org/docs/reference/visibility-modifiers.html" rel="nofollow noreferrer">https://kotlinlang.org/docs/reference/visibility-modifiers.html</a>, it seems that <em>"private means visible inside this class only (including all its members);"</em> for Classes and Interfaces.</p>
  
  <p>Would you please see the image?</p>
  
  <p><a href="https://i.stack.imgur.com/72977.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/72977.png" alt="enter image description here"></a></p>
  
  <p><strong>To yole:</strong></p>
  
  <p>Thanks! I can't access a private member in the class MyB outside  companion object by the following code.</p>
  
  <pre><code>class UIPreference {
  
      companion object {
          private val aa=1
  
      }
  
      class MyA {
          private val bar: Int =UIPreference.aa  //OK
      }
  
  }
  
  
  class MyB {
     private val bar: Int = UIPreference.aa //Failed
  }
  </code></pre>