Skip to content

Commit 51e687c

Browse files
committed
added access modifier
1 parent 5cbcf97 commit 51e687c

File tree

3 files changed

+82
-3
lines changed

3 files changed

+82
-3
lines changed

.idea/workspace.xml

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Encapsulation/AcessModifier.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
### Access Modifiers in Java
2+
3+
There are two types of modifiers in Java: access modifiers and non-access modifiers.
4+
5+
The access modifiers in Java specifies the accessibility or scope of a field, method, constructor, or class. We can change the access level of fields, constructors, methods, and class by applying the access modifier on it.
6+
7+
There are four types of Java access modifiers:
8+
9+
- Private: The access level of a private modifier is only within the class. It cannot be accessed from outside the class.
10+
- Default: The access level of a default modifier is only within the package. It cannot be accessed from outside the package. If you do not specify any access level, it will be the default.
11+
- Protected: The access level of a protected modifier is within the package and outside the package through child class. If you do not make the child class, it cannot be accessed from outside the package.
12+
- Public: The access level of a public modifier is everywhere. It can be accessed from within the class, outside the class, within the package and outside the package.
13+
14+
There are many non-access modifiers, such as static, abstract, synchronized, native, volatile, transient, etc. Here, we are going to learn the access modifiers only.
15+
16+
##### Understanding Java Access Modifiers
17+
18+
|Access Modifier |within class | within package| outside package by subclass only |outside package|
19+
|------|--------|------|---------|----------|
20+
|Private| Y| N| N| N|
21+
|Default |Y| Y |N |N|
22+
|Protected| Y |Y| Y| N|
23+
|Public| Y| Y|Y |Y|
24+
25+
-------
26+
27+
28+
29+

src/Encapsulation/Package.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
### Java Package
2+
3+
A java package is a group of similar types of classes, interfaces and sub-packages.
4+
5+
Package in java can be categorized in two form, built-in package and user-defined package.
6+
7+
There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc.
8+
9+
Here, we will have the detailed learning of creating and using user-defined packages.
10+
11+
##### Advantage of Java Package
12+
13+
1) Java package is used to categorize the classes and interfaces so that they can be easily maintained.
14+
15+
2) Java package provides access protection.
16+
17+
3) Java package removes naming collision.
18+
19+
![](https://static.javatpoint.com/images/package.JPG)
20+
21+
### Simple example of java package
22+
23+
```java
24+
package mypack;
25+
public class Simple{
26+
public static void main(String args[]){
27+
System.out.println("Welcome to package");
28+
}
29+
}
30+
```
31+
32+
-----
33+
34+
##### How to access package from another package?
35+
36+
There are three ways to access the package from outside the package.
37+
38+
1- import package.*;
39+
40+
2- import package.classname;
41+
42+
3- fully qualified name.
43+
44+
45+
46+
-----
47+
48+

0 commit comments

Comments
 (0)