as for my observation when the class itself is having default access modifier, what is the use of having public methods in it. the java compiler could have stopped using public methods in default class. is there any reason for that?
The public keyword is an access modifier, meaning that it is used to set the access level for classes, attributes, methods and constructors.
By Default the access specifier for Main() in C# is private.
internal is the default if no access modifier is specified. Struct members, including nested classes and structs, can be declared public , internal , or private . Class members, including nested classes and structs, can be public , protected internal , protected , internal , private protected , or private .
Public Access Modifier It is a keyword. If a class member like variable, method, or data members are prefixed with a public access modifier, then they can be accessed from anywhere inside the program. That is, they can be accessed within the same class as well as from outside the different classes.
The non-public class might implement a public interface. This would mean that classes outside of the package could not create an instance of this class or create references of that type, but they would still be able to invoke methods on it if passed an instance.
For example, a public factory class might create an instance of an non-public class in its package and return it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With