Operators and Assignments

Q1: What will be the output of the program?
class Test 
    static int s;
    public static void main(String [] args) 
        Test p = new Test();

    void start() 
        int x = 7;
        System.out.print(x + ' ');

    void twice(int x) 
        x = x*2;
        s = x;

A 14 14

B 7 14

C 7 7

D 14 0

ANS:A - 7 7

The int x in the twice() method is not the same int x as in the start() method. Start()'s x is not affected by the twice() method. The instance variable s is updated by twice()'s x, which is 14.

img not found

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.