Professional Documents
Culture Documents
Access Modifiers
Access Modifiers
By:
Prof. Monika Gadre
Prof. Monika Gadre
Prof. Monika Gadre
Prof. Monika Gadre
Question 1
Trace the output
private class AA
{
public int a=10;
}
A class can only be declared as public or default.
Private and protected are not allowed for a class
definition.
^
Question 4
Trace the output
package A; package B;
import A.AA;
public class AA class AAA{
{ public static void main(String a[]){
public int x=10; System.out.println(x);
int y=20; System.out.println(y);
private int z=30; System.out.println(z);
protected int w=40; System.out.println(w);
} }
Output: only public data member i.e., x is accessible in the class AAA that is another package.
Whereas y, z, w are not accessible though the class AA is public.
Prof. Monika Gadre