Answers for "arious access modifiers available in java"

0

What all access modifiers are allowed for top class

For top level class only two access modifiers are allowed. 
public and default. If a class is declared as public it is visible everywhere.
If a class is declared default it is visible only in same package.
If we try to give private and protected as access modifier to class 
we get the below compilation error.
Illegal Modifier for the class only public,abstract and final are permitted.
Posted by: Guest on November-30-2020
1

what access modifiers can be used for methods

We can use all access modifiers public, private,protected and default for 
methods.
public : When a method is declared as public it can be accessed
6) In the same class
7) In the same package subclass
8) In the same package nonsubclass
9) In the different package subclass
10) In the different package non subclass.
default : When a method is declared as default, we can access that method in
1) In the same class
2) In the same package subclass
3) In the same package non subclass
We cannot access default access method in
1) Different package subclass
2) Different package non subclass.
protected : When a method is declared as protected it can be accessed
1) With in the same class
2) With in the same package subclass
3) With in the same package non subclass
4) With in different package subclass
It cannot be accessed non subclass in different package.
private : When a method is declared as private it can be accessed only in 
that class.
It cannot be accessed in
1) Same package subclass
2) Same package non subclass
3) Different package subclass
4) Different package non subclas
Posted by: Guest on November-30-2020
0

What all access modifiers are allowed for top class

For top level class only two access modifiers are allowed. 
public and default. If a class is declared as public it is visible everywhere.
If a class is declared default it is visible only in same package.
If we try to give private and protected as access modifier to class 
we get the below compilation error.
Illegal Modifier for the class only public,abstract and final are permitted.
Posted by: Guest on November-30-2020
1

what access modifiers can be used for methods

We can use all access modifiers public, private,protected and default for 
methods.
public : When a method is declared as public it can be accessed
6) In the same class
7) In the same package subclass
8) In the same package nonsubclass
9) In the different package subclass
10) In the different package non subclass.
default : When a method is declared as default, we can access that method in
1) In the same class
2) In the same package subclass
3) In the same package non subclass
We cannot access default access method in
1) Different package subclass
2) Different package non subclass.
protected : When a method is declared as protected it can be accessed
1) With in the same class
2) With in the same package subclass
3) With in the same package non subclass
4) With in different package subclass
It cannot be accessed non subclass in different package.
private : When a method is declared as private it can be accessed only in 
that class.
It cannot be accessed in
1) Same package subclass
2) Same package non subclass
3) Different package subclass
4) Different package non subclas
Posted by: Guest on November-30-2020

Code answers related to "arious access modifiers available in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language