Menu
Topics Index
...
`

Static keyword


If you need explanation Read this topic

If you need Answer Take test on this topic

Static keyword
What will be the output of the following program
public class Time {
    int a = 50;
    int b = 10;
    public static void main(String args[]) {
        a += b--;
        System.out.println(a);
    }
}

A. 60
B. 50
C. 59
D. 49
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.

Ans is A..

Posted by Om Prakash Om    2013-09-06 04:00:29


answer is e because non static variable scannot be referenced from static context

Posted by Shashanka Mogaliraju    2013-09-06 04:01:05


answer is c

Posted by Shiva Goud    2013-09-06 04:25:22


59 is answer because a=a+b-- gives sum of a value + decremented b value i.e., 9.(b-- mean first it takes value and decrements the value that is taken)

Posted by Racha Rajesh    2013-09-06 04:29:23


E might be the anwser...since non static variable..

Posted by Shabaaz Shaikz    2013-09-06 05:01:07


int a and b should be declared inside main function then answer wld be 59..since it is declared out of main function...compilation error may occurs...

Posted by Shabaaz Shaikz    2013-09-06 06:38:04


The correct answers are given by Shashanka Mogaliraju and Shabaaz Shaikz, but accordingly to the rules none of them get the recharge since Shashank already won and Shabaaz wrote two comments.

Posted by Merit Campus    2013-09-08 11:57:10


Just for this time we will ignore the rules and give them the recharge. Shashank, Shabaaz we will send the links using which you can claim your recharge.

Posted by Merit Campus    2013-09-08 11:58:33


© meritcampus 2019

All Rights Reserved.

Open In App