Write a program in java to demonstrate static method and Variable?

class StaticDemo

{

                static int a=9;

                int b=7;

                public void display()

                {

                                System.out.println(a);

                                System.out.println(b);

                }

                public static void print()

                {

                                System.out.println(a);

                }

                public static void main(String arg[])

                {

                                StaticDemo x=new StaticDemo();

                                x.display();

                                StaticDemo.print();

                }

}

Static Method & Variable.PNG

, , , , , , ,

Leave a Reply