Sunday 20 February 2011

static keyword questions in java


Questions of static keyword in java and answers

(1)



class StaticDemo {

    static int a=0;

    int b=++a;

    static int c=++a;



    public static void main(String[] args){

         System.out.print(c);

    }

}



What will be output of above program?

         

(a)0

(b)1

(c)2

(d)Compiler error













Answer: (b)



(2)



class StaticDemo {

    int a=0;

    int b=++a;

No comments:

Post a Comment