What does static mean? - Cracking the Java Coding Interview

preview_player
Показать описание
Cracking the #Java #Coding #Interview - Question 103: What does static mean?
Рекомендации по теме
Комментарии
Автор

The `static` keyword can also be applied to nested classes (not just fields, methods, and initializer blocks).
It is also used for static imports.

jay_
Автор

"All your instance share this field"

With slight remark that class/type inisde single JVM process is identified by package name, class name and class loader name.

So if you load contents from same class file using two different class loaders you'll have two distinct Class<> objects each having their own static members. (If it's loaded without delagating to super())

If you then use reflection to cretae instances from those class objects, just those created from same object will share same field.

Also, none of those instance can be cast in code to the type "they came from". I think it's because when literal name of the class is used in code, that refers to class loaded by app class loader. Neither will instanceof pass on those reflectively created instances.

I

KING
Автор

Using mutable static field is a trouble so true

ares
Автор

Hi..
What is an array in java?
From where we are creating object for array ?
If [I is the class then why we are creating int[]
Where I can see the implementation of array?
Can u pls do a short video about a array?

MuraliKrishna-bnqd
Автор

Hello, I have a question about static block in the class… If I have to initialize a static field but the value is returned by a method that throws a checked exception (like Class.forName(…)). What is the correct way to initialize it? I actually add a static block and then initialize it in a try catch

pesterstone
Автор

When should we declare a method as static vs nonstatic

MakeItStik
Автор

Static means Global effectively.
It is accessible form anywhere xD

Also "dont use the static {} its an antipattern".
Are you kidding me?
Static is used to actually init all static fields in the sourcecode xD

Speiger
Автор

Explain annotations with simple example

sivakumar.s
Автор

I don't know if it's only me but this act of drinking something and trying to explain something is very irritating

RealThinkCenter
visit shbcf.ru