What will be the output of following Java code (4)?

50. What will be the output of following Java code?

import java.util.Scanner;

class ThisKeyword {
  private int a = 4;
  private int b = 1;

  void getSum(int a, int b) {
    this.a = a;
    this.b = b;
    System.out.println(this.a + this.b);
  }
}

public class Main {
  public static void main(String args[]) {
    ThisKeyword T = new ThisKeyword();
    T.getSum(3, 5);
  }
}
  1. Error
  2. 8
  3. 5
  4. None of these

Answer: B) 8

Explanation:

The output of the above program is:

8

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.