Static and access modifiers







  Aim  of this program  is to  show static  values behave in program. Also protracted access.



  public class MyStat {


 

     final  int i =10;

     static int  j=9;

     protected  int m=56;

     private  int n=100;

     public  int  z=200;

        


  

    

public static void main(String  args[]){

  

  

         MyStat  t=new MyStat();

       

      

           System.out.println(" Final  int " +t.i);


           System.out.println(" Final  int " +t.j);


           System.out.println(" Final  int " +t.m);


           System.out.println(" Final  int " +t.n);


           System.out.println(" Final  int " +t.z);

   

                  j=99;

              

                  

                  t.z=500;

               

               

          //  t.i=6;   error it is  final.

            

              

        System.out.println(" after changed value static J="+j);

        

        System.out.println( "**after changed public int z=" +t.z);

        

       

        

          MyStat  t2=new MyStat();

        

          System.out.println(" after changed value static J="+j);

          

          System.out.println( "**after changed public int z=" +t2.z);

          

  

            MyStatmod tmd=new MyStatmod();

        

                    int jvalue=tmd.accessmod();

  

         System.out.println( "Value of protacted  j in subclass "+jvalue );

  

  

  }

 

}



 class   MyStatmod extends MyStat {

 

 

  public int  accessmod(){

  

   return  j=900;  // accessible here

   // return  n=1000  error  it is private ;


  }

 }


 Program Output :--


 Final  int 10

 Final  int 9

 Final  int 56

 Final  int 100

 Final  int 200

 after changed value static J=99

**after changed public int z=500

 after changed value static J=99

**after changed public int z=200

Value of protacted  j in subclass 900


   


Static and access modifiers Static  and access modifiers Reviewed by Mukesh Jha on 12:55 AM Rating: 5

No comments:

Add your comment

All Right Reserved To Mukesh Jha.. Theme images by Jason Morrow. Powered by Blogger.