Why can I access a private variable from main method?

后端 未结 7 784
一整个雨季
一整个雨季 2020-12-06 06:24
package com.valami;

 public class Ferrari
 {
  private int v = 0;


  private void alam()
  {
   System.out.println(\"alam\");
  }

  public Ferrari()
  {
   System         


        
相关标签:
7条回答
  • 2020-12-06 07:22

    As long as the private variable is in the same class as the main() method, then the main() method has access to it. In general, even static methods have access to private fields of instances of the same class.

    0 讨论(0)
提交回复
热议问题