हिंदी

Write a Java application that illustrates member variables (class and instance), local variables, and method parameters.

Advertisements

प्रश्न

Write a Java application that illustrates member variables (class and instance), local variables, and method parameters.

कोड लेखन
Advertisements

उत्तर

class VariableDemo 
{
    static int count = 10;
    int number = 20;
    void display(int value)
    {
        int sum = number + value;
        System.out.println("Class Variable: " + count);
        System.out.println("Instance Variable: " + number);
        System.out.println("Method Parameter: " + value);
        System.out.println("Local Variable: " + sum);
    }

    public static void main(String[] args) 
    {
        VariableDemo obj = new VariableDemo();
        obj.display(30);
    }
}

Output:

Class Variable: 10
Instance Variable: 20
Method Parameter: 30
Local Variable: 50
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 6: Variables and Expressions - SHORT ASSIGNMENTS [पृष्ठ १३६]

APPEARS IN

धीरज मेहरोत्रा Computer Science [English] Class 12
अध्याय 6 Variables and Expressions
SHORT ASSIGNMENTS | Q 38. | पृष्ठ १३६
Advertisements
Share
Notifications



      Forgot password?
Use app×