Skip to main content

Posts

Showing posts with the label Static and this keyword

Static and this keyword

Static Keyword:      Most of the time static keyword in java use for memory management. We can use static keyword with variables, methods and also with block (Static block) . 1. Static with variables:     If we declare static keyword with variables then it's called static variables . Static variables are use to access or refer common properties of all objects. The static varibels gets memory only once at the time of loading class loading. It makes program more efficient i.e., It saves memory. For example,     static int length=100; 2. Static with method:     If we use static keyword with method then it's called static method . The static method is belong to class rather than object of class. Static method can invoke or call without creating instance or object of class. For example,     static void print(){          System.out.println("Welcome in Java");     } Examples of static variable, method an...