Morning Everybody
In this article today we are going to learn " Introduction of packages and access modifier in Java ". So let`s get started.
A package is group of java classes, interfaces and sub packages. There are types of packages.
In this article today we are going to learn " Introduction of packages and access modifier in Java ". So let`s get started.
1) Packages:
A package is group of java classes, interfaces and sub packages. There are types of packages.
1) Built-in packages:
Java provide many built in packages like java, lang, util, sql etc.
2) User Define packages:
User can create own package is call user define package.
2) User Define packages:
User can create own package is call user define package.
2) Access Modifier:
It defines the accessibility of data member (Variable) and member method (function). There are four types of access modifier in java are as follows:
1) Public:
If we assign public access modifier to class members than it can access by any class.
2) Default:
If we assign don`t any access modifier to class members than it treated as default. It behaves like public access modifier in same package.
3) protected:
If we assign protected access modifier to class members than it can access in same class and it`s child class and also use in other package with inheritance.
4) Private:
If we assign private access modifier to class members than it can access by same class public members only.
If we assign public access modifier to class members than it can access by any class.
2) Default:
If we assign don`t any access modifier to class members than it treated as default. It behaves like public access modifier in same package.
3) protected:
If we assign protected access modifier to class members than it can access in same class and it`s child class and also use in other package with inheritance.
4) Private:
If we assign private access modifier to class members than it can access by same class public members only.
Thank you. Have a nice day.
" Be Student , Be Curious "
For more detail watch this video :
No comments:
Post a Comment