Can I say a static variable is like a global variable? So local variables can only be shared/used among the instance/object. But a global variable can be used by the entire class and every instance/object belonging to that class?
Very helpful ! When creating the variable static name, you said that the name property of obj1 and obj2 will share the same static name, the static name is stored in an area in the heap memory, then the name attribute of obj1 and the name attribute of obj2 are in memory heap will contain the address of the static name in the heap memory right?
But when we access static variable with object ref then we can change the value of static variable for all the objects then how its maintain rule of common for all (Belong to class ) or its just behaves like instance variable with hard core value ???? Is Memory saving the only difference ???
Yes when we make a common variable for all the objects we don't need to initialize it with each object so memory saving is the advantage of using static.
less memory is used for instance if you declare 3 non static integer variables then each object will occupy 12 bytes of memory ..if there are 3 objects total will be 36 but if you declare one static variable and if the other 2 are non static then static variable will take its 4 bytes which will be shared with all objects and each object will separately take its 8 bytes of storage..so total memory that is used for 3 objects will be 24 bytes and 24+4 is 28 bytes...
Your explanation of static variable helps to understand static keywords better. Thanks.
still can't believe you're providing this level of content free..
Thank You ..After a long time I got to know the real reason for creating the show method
Can I say a static variable is like a global variable? So local variables can only be shared/used among the instance/object. But a global variable can be used by the entire class and every instance/object belonging to that class?
thanks dear theacer your Student from Afghanistan
Great explanation!
Very helpful !
When creating the variable static name, you said that the name property of obj1 and obj2 will share the same static name, the static name is stored in an area in the heap memory, then the name attribute of obj1 and the name attribute of obj2 are in memory heap will contain the address of the static name in the heap memory right?
Great explanation
But when we access static variable with object ref then we can change the value of static variable for all the objects then how its maintain rule of common for all (Belong to class ) or its just behaves like instance variable with hard core value ???? Is Memory saving the only difference ???
Yes we can access with object reference but it will reflect in all the objects so it is called common area.
Yes when we make a common variable for all the objects we don't need to initialize it with each object so memory saving is the advantage of using static.
nice explanation sir
Well explained 🎉❤
excellent explain static
Sir I had an interview yesterday what is the significance of static variable .I don't know can you explain
less memory is used for instance if you declare 3 non static integer variables then each object will occupy 12 bytes of memory ..if there are 3 objects total will be 36 but if you declare one static variable and if the other 2 are non static then static variable will take its 4 bytes which will be shared with all objects and each object will separately take its 8 bytes of storage..so total memory that is used for 3 objects will be 24 bytes and 24+4 is 28 bytes...
Thankyou !
Well explanation
By the way price of an apple is lower than price of samsung... Must throw an error
wkwk
New learning "static variables should be called with there class name".
Sir where the static variable is stored ?? Inside stack memory or Heap memory ?
heap memory
Inside static nd global memory of heap
Why are you not updating VS Code? Please update VS Code.