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

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);
  }
}
  • (A) 5
  • (B) 9
  • (C) 8
  • (D) 4
πŸ’¬ Discuss
βœ… Correct Answer: (C) 8
Explanation: The above Java program is an example to demonstrate the use of this keyword.
Explanation by: Team MCQ Buddy
The above Java program is an example to demonstrate the use of this keyword.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
402
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Ram Sharma
Publisher
πŸ“ˆ
96%
Success Rate