Computer Science, asked by anaborah77, 6 months ago

what is the difference between static and instance variable?​

Answers

Answered by khaathwiksanivada
1

Answer:

Instance variables are created when an object is created with the use of the keyword 'new' and destroyed when the object is destroyed. Static variables are created when the program starts and destroyed when the program stops. Instance variables can be accessed directly by calling the variable name inside the class.

Explanation:

Hope this will help u.......

Have a great day

plz mark me brainliest

Answered by anindyaadhikari13
4

Question:-

What is the difference between static and instance variables?

Answer:-

The main differences are as follows:-

  1. Static variables are declared with keyword static whereas Instance variables are declared without static keyword.
  2. Static variables are common to all instances of a class whereas instance variables are not shared between the objects of a class.
  3. Static variables can be accessed using either class name or object reference whereas instance variables can be accessed only through object reference.
Similar questions