Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

method without access modifier

Ok this is bugging me.. I know I've read it somewhere and google isn't helping.

What is the accessibility level of a method that does not specify an access modifier?

void Foo() {     //code }  

I want to say internal but I'm not 100% sure.

like image 401
Leroy Jenkins Avatar asked May 26 '10 23:05

Leroy Jenkins


People also ask

What if no access modifier is specified Java?

Default: When no access modifier is specified for a class, method, or data member – It is said to be having the default access modifier by default. The data members, class or methods which are not declared using any access modifiers i.e. having default access modifier are accessible only within the same package.

When an interface method has no access modifier it is?

If no access modifier is given, the method is implicitly public .

What is the visibility of a class without an access modifier?

If a class has no modifier (the default, also known as package-private), it is visible only within its own package (packages are named groups of related classes — you will learn about them in a later lesson.)

What happens if you don't declare access modifiers?

Is it true that if you don't specify an access modifier for an interface, that interface will have default access? Yes that is true. Java types/fields/methods (in class) have package-level access if access modifier is not specified. Members defined in inteface type are public by-default.


1 Answers

The default accessibility for a type is internal, but the default accesibility of that type's members depends on the type.

Generally speaking, members of a class are private by default, where as members of a struct are public by default. This varies by language; default struct access modifiers for C++ are public, where as for C#, they are private.

like image 147
Steve Guidi Avatar answered Oct 11 '22 13:10

Steve Guidi