REGISTER FREE to Receive Instant Job

Sunday, 28 October 2012

Concept of Static Keyword in Java

static Keyword: Is used to define class members. In a class we can have following 3 types of class members:-
  1. STATIC DATA MEMBERS: - Represents class attributes. A single copy of static data members is created when the class is loaded. This copy can be shared by all the objects of the class.
  • For example -
    class A
    {                int a, b;
                    static int c;
    2.  STATIC INITIALIZE BLOCK : Static Initializer Block- is used to initialize static data members of a class.
  • Syntax –
    Static initialize is executed only once, just after a class is loaded.
class A
{                int a, b;
                static int c;
                public static void main(String[] args)
                                A x = new A();
                                A y = new A();
Limitations of static methods & static block:-
    • Only static data members of a class can be referred in a static block or method.
    • A static block or static method can directly invoke only static methods.
    • ‘this’ and ‘super’ keyword cannot be used in a static method or in  a static block
  • For More Details 

1 comment:

Popular Posts

Powered by Blogger.

About Me

My photo

JobsAcid is a 'job search engine' to provide finding a job on the internet easier for the user. It has designed as huge selection of job offerings on the same search engine.