Header Ads

Access Modifiers in java | Default Modifier 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."
 



Steps to Subscribe my blog in 15 secs:
1. Enter your mail id in "Subscribe" box.
2. Enter Captcha for verification.
3. A mail will be received with link in your mail id.Just Click on link  and  then Done .Thank you for subscribing :)

No comments

Note: Only a member of this blog may post a comment.