Java – is the public modifier in the private class of the package redundant?

Suppose I'm in package com Test in test Java declares a class test:

I want to know, isn't the public access modifier of method test () redundant? Because IntelliJ didn't give me a hint that it was

I think I am redundant only when the test class contains public static void main (string [] args) {}? Am I right or wrong?

Solution

This is not superfluous If you have some derived classes, modifiers can make a huge difference Consider these courses:

And another derived test Class

Now, when we have another derived testderive Class, you can see different behaviors on methods In this case, the class has a public modifier

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>