Menu
Question Index
...

What will be the output of the following program?

public class NValueIs {
    public static void main(String[] args) {
        int num1 = 1;
        int num2 = 2;
        System.out.println("Before swap method, num1 is " + num1 + " and num2 is " + num2);
        swap(num1, num2);
        System.out.println("After swap method, num1 is " + num1 + " and num2 is " + num2);
    }
    public static void swap(int n1, int n2) {
        int temp = n1;
        n1 = n2;
        n2 = temp;
    }
}


Before swap method, num1 is 1 and num2 is 2
After swap method, num1 is 2 and num2 is 1
Before swap method, num1 is 1 and num2 is 2
After swap method, num1 is 1 and num2 is 2
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Static Keyword In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App