Explain the various types of Variables in JAVA.
Advertisements
प्रश्न
Explain the various types of Variables in JAVA.
स्पष्ट करा
Advertisements
उत्तर
- Local Variables: Local variables are declared inside a method, constructor or block. They can be accessed only within the block in which they are declared. These variables must be initialized before use.
- Instance Variables: Instance variables are declared inside a class but outside any method, constructor or block. Each object of the class has its own copy of these variables. Their values may differ from one object to another.
- Static Variables (Class Variables): Static variables are declared inside a class but outside any method or constructor using the
statickeyword. These variables are shared by all objects of the class, and only one copy exists for the entire class.
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
