2 min read

Static function are usefull when the function is called only once or we don’t need multiple copies of that function.

 A static method can access only static members. A non-static method can access both static and non-static members.

Static function can be called either by class name or object .A non static function can be called only by object.

Example:-

class example

{

          static void func1()

          {                 

                   System.out.println(“Function 1”);

          }

          void func2()

          {

                   System.out.println(“Function 2”);

          }

          public static void main(String args[])

          {

                   example obj=new example();

                   example.func1();

                obj.func1();

                obj.func2();

          }

}       

                          


Vinay007

I am a loving person with helping nature.Quite introvert but love to express myself to loved ones.Big fan of Army and Mahadev ,yeah I am religious , interested in spirituality and yoga is the ultimate goal.I like to explore new places ,love to ride on adventures ,want to live in every moment and feel every second of life.

0 Comments

Leave a Reply