In the program given below, state the name and the value of the:

  1. method argument or argument variable
  2. class variable
  3. local variable
  4. instance variable

class MyClass{
    static int x = 7;
    int y = 2;
    public static void main(String args[]){
        MyClass obj = new MyClass();
        System.out.println(x);
        obj.sampleMethod(5);
        int a = 6;
        System.out.println(a);
    }
    void sampleMethod(int n){
        System.out.println(n);
        System.out.println(y);
    }
}

Views 12

Answer:

Answer

  1. Method argument/Argument variable is n
  2. Class variable is x
  3. Local variable is a
  4. Instance variable is y

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.