Why am I able to call private method?

后端 未结 8 1468
深忆病人
深忆病人 2020-12-10 21:29

I should not be able to invoke a private method of an instantiated object. I wonder why the code below works.

public class SimpleApp2 {
    /**
     * @param         


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 21:46

    Your main method is a method of SimpleApp, so it can call SimpleApp's private methods.

    Just because it's a static method doesn't prevent it behaving like a method for the purposes of public, private etc. private only prevents methods of other classes from accessing SimpleApp's methods.

提交回复
热议问题