Access Modifiers in java | Default Modifier in java
Default Modifier in java
Default Classes:
If a class declared with default modifier then we can access that class only within the current package hence default access is also called as "package level access".
Example:
Program 1:
package pack1;
class Abc
{
public void methodOne()
{
System.out.println("Abc class methodone is executed");
}
}
Program 2:
package packl;
import pack1.Abc;
class Test1
{
public static void main(String args[])
{
Abc a=new Abc();
a.methodOne();
}
}
OUTPUT:
javac Abc.java ----------------------->(run on cmd)
javac Testl.java ----------------------->(run on cmd)
java pack1.Test1 -------------------->(run on cmd)
Abc class methodone is executed --->(output on cmd)
An Inspirational quote:
"You can either experience the pain of discipline or the pain of regret. The choice is yours."
Post a Comment