Saturday, 20 April 2019

Java Static post_1

1)   Static data members and member function can be called using class name

*********************************PROGRAM**************************************


class sam
{
    static int a=10;
    static void fun()
    {
        System.out.println("In fun()");
    }
}
class sample
{
    public static void main(String args[])
    {
        System.out.println("a : "+sam.a);
        sam.fun();
    }
}


*********************************OUTPUT************************************

a : 10
In fun()
__________________________________________________________________________________

2) Static variables get memory in data segment if static variable is initialized.
      If variable is not initialized it get memory in BSS segment.
__________________________________________________________________________________