πŸ“Š JAVA
Q. What will be the output after compiling and running following program code?
Code:
public class Test{
      static int a;
      public static void main(String[] args){
            System.out.println("one");
            call(1);
      }

      static void call(int a){
            this.a=10;
            System.out.println("two "+a);
      }
}
  • (A) one two 1
  • (B) one two 10
  • (C) one two 0
  • (D) one two 0D.Compile time error.
πŸ’¬ Discuss
βœ… Correct Answer: (D) one two 0D.Compile time error.

Explanation: Static members are common for all objects, where as ‘this’ refer to a particular object. so we cant use ‘this’ operator in the static methods.

Explanation by: Pooja
Static members are common for all objects, where as ‘this’ refer to a particular object. so we cant use ‘this’ operator in the static methods.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
74
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Pooja
Publisher
πŸ“ˆ
87%
Success Rate