Java Modifiers
Modifiers are keywords that nosotros add together to those definitions to alter their meanings.
There are Two types of modifiers inward Java.
a) Access Modifiers
b) Non-access Modifiers
---------------------
a) Access Modifiers
There are four types of modifiers inward Java.
we utilization access modifiers to define access command for classes, methods together with variables etc...
1) private
2) default
3) protected
4) public
---------------------
1) private:
The someone access modifier is accessible solely within class.
Ex:
class H5N1 {
private int a = 40;
.
.
---------------------
2) default
If nosotros don't utilization whatever modifier, it is treated every bit default past times default. this tin hand notice live accessible solely within package.
Ex:
package abc;
class Sample {
int a;
.
.
---------------------
3) protected
The protected access modifier is accessible within package, together with out side of the packet but through Inheritance only.
Ex:
---------------------
4) public
public access modifier is accessible everywhere. It has widest orbit alongside all other modifiers.
Ex:
public Class A{
public static void master copy (String [] args) {
.
.
b) Non-access Modifiers
Java provides no of non access modifiers to accomplish many other functionality.
Static modifier to practise class, methods together with variables.
Ex:
class Abc {
static String advert ="Selenium"
.
.
--------------------------------
final modifier for finalizing the implementation of classes, methods together with variables.
Ex:
class Sample {
final int a =100;
-------------------------
abstract modifier is to practise abstract classes together with methods.
public abstract Sample {
.
.
etc...
---------------------------------------
Also Read:
Java Variables
Java Operators
Java Conditional Statements
Java Loop Statements
Java Arrays
Java Methods
Sumber http://www.gcreddy.com/
Modifiers are keywords that nosotros add together to those definitions to alter their meanings.
There are Two types of modifiers inward Java.
a) Access Modifiers
b) Non-access Modifiers
---------------------
a) Access Modifiers
There are four types of modifiers inward Java.
we utilization access modifiers to define access command for classes, methods together with variables etc...
1) private
2) default
3) protected
4) public
---------------------
1) private:
The someone access modifier is accessible solely within class.
Ex:
class H5N1 {
private int a = 40;
.
.
---------------------
2) default
If nosotros don't utilization whatever modifier, it is treated every bit default past times default. this tin hand notice live accessible solely within package.
Ex:
package abc;
class Sample {
int a;
.
.
---------------------
3) protected
The protected access modifier is accessible within package, together with out side of the packet but through Inheritance only.
Ex:
---------------------
4) public
public access modifier is accessible everywhere. It has widest orbit alongside all other modifiers.
Ex:
public Class A{
public static void master copy (String [] args) {
.
.
Modifier | Within class | Within Package | Outside of the Package (by sub classes) | Outside of the Package |
Private | Y | N | N | N |
Default | Y | Y | N | N |
Protected | Y | Y | Y | N |
Public | Y | Y | Y | Y |
Java provides no of non access modifiers to accomplish many other functionality.
Static modifier to practise class, methods together with variables.
Ex:
class Abc {
static String advert ="Selenium"
.
.
--------------------------------
final modifier for finalizing the implementation of classes, methods together with variables.
Ex:
class Sample {
final int a =100;
-------------------------
abstract modifier is to practise abstract classes together with methods.
public abstract Sample {
.
.
etc...
---------------------------------------
Also Read:
Java Operators
Java Conditional Statements
Java Loop Statements
Java Arrays
Java Methods