0% found this document useful (0 votes)
10 views4 pages

Aug 4

Uploaded by

MONICA NAHAK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

Aug 4

Uploaded by

MONICA NAHAK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Dt : 9/8/2023

faq:

define Access modifiers in Java?

=>Access modifiers in Java will specify the scope of programming components

within the JavaProject.

i
=>The following are some important access modifiers in Java:

thi
1.public

2.private

ipa
3.protected

4.default
Ma
1.public:
sh
=>"public" programming components are accessed within the JavaProject.
ate

2.private:
nk

=>"private" programming components are accessed within the class only.


Ve

3.protected:

=>"protected" programming components are accessed within the package.

4.default:
=>The programming components which are declared without any access
modifiers

are considered as default.

=>default programming components are accessed within the package.

Diagram:

i
thi
ipa
Ma
sh
ate
nk

------------------------------------------------------------------------

faq:
Ve

wt is the difference b/w

(i)protected

(ii)default

=>"protected" programming components are available to ChildClasses which


are
outside the package,but default programming components are not available to

ChildClasses.

===================================================================
==========

Ex:

ProjectName : AccessModifers_App

i
thi
packages,

p1 : ClassA.java

ipa
package p1;
public class ClassA
{ Ma
public int a=10;
private int b = 20;
protected int c= 30;
int d=40;
}
sh
ate

p2 : ClassB.java
package p2;
import p1.ClassA;
public class ClassB
nk

{
public ClassA ob = new ClassA();//NonPrimitive
Ve

Instance variable
public void dis()
{
System.out.println("Value a : "+ob.a);
//System.out.println("Value b : "+ob.b);
//System.out.println("Value c : "+ob.c);
//System.out.println("Value d : "+ob.d);
}
}
p3 : DemoMain.java(MainClass)
package p3;
import p2.ClassB;
public class DemoMain {
public static void main(String[] args) {
ClassB ob2 = new ClassB();
ob2.dis();

i
}

thi
}

ipa
===============================================================

Ma
sh
ate
nk
Ve

You might also like