+ 2

What is static in Java?

Java Interviewers asked question?

19th Oct 2017, 11:17 AM
Mangesh Suresh Tambat
Mangesh Suresh Tambat - avatar
1 Odpowiedź
+ 5
Dang. If I go for an interview that's the question of my dreams. lol. Static makes the member bound to the class itself. Meaning, there will only be one of the member allocated to the stack memory. For Example, if we have a variable that is static and create multiple instances of the class; we will still only have the one static variable that will be shared between all those Objects. If we have a method, we can call the method without having to even create an Object. Also, as @Uvaish said, we can do the same for variables (accessing them without an Object). This is due to static not being part of an Object, rather being part of the class itself. This also means a static member cannot be overrided.
19th Oct 2017, 4:43 PM
Rrestoring faith
Rrestoring faith - avatar