Menu
Topics Index
...
`

Creating Static variable Method and blocks


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating Static variable Method and blocks
What will be the output of the following program?
public class Sketch {
    static int ad = 100;
    static int bc = 200;
    static {
        ad += 1;
        bc += 1;
    }
    public static void main(String args[]) {
        ad += 5;
        bc += 10;
        System.out.println(ad + bc);
    }
    static {
        ad += 100;
        bc += 200;
    }
}

A. 317
B. 615
C. 617
D. 315
E. Compilation Error or Runtime Error
Topic: Static Keyword In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Answer is C,
617 because first static method gets execute.
100+1,200+1
101+100,201+200
then 201+5,401+10
617 will be printed

Posted by Amar Kumar Biradar    2013-09-03 08:36:46


C...wd above explanation

Posted by Bhavya Rishitha    2013-09-03 09:43:24


ans b:

Posted by Sravan Haram    2013-09-03 09:49:53


answer is d variables in main block are not affecetd static block variable values.

Posted by Shiva Goud    2013-09-03 10:12:26


Congratulations Amar Kumar Biradar. You are this dose winner. Please send us your mobile details in a private message and we will process the recharge asap.

Posted by Merit Campus    2013-09-04 04:19:57


Thanks Merit Campus :)
I have got Recharge =D

Posted by Amar Kumar Biradar    2013-09-05 04:07:50


© meritcampus 2019

All Rights Reserved.

Open In App