Menu
Question Index
...

What will be the output of the following program?

public class HaiTwice {
    static int num;
    public static void main(String[] args) {
        HaiTwice p = new HaiTwice();
        p.start();
        System.out.println(num);
    }
    void start() {
        int var = 7;
        twice(var);
        System.out.print(var + " ");
    }
    void twice(int var) {
        var = var * 2;
        num = var;
    }
}


7 7
7 14
14 0
14 14
Compilation Error or Runtime Error

Doubts

Problems

Topic: Static and Non Static Variables - Static and Non Static Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App