0
What does static mean?
11 Respostas
+ 1
With static variables in one class you get access directly to it from out of that class whit no need for instantiating of an object from class as well as with static methods in one class that methods become independent of made objects and behaves independently
+ 1
Static is a keyword. The role of adding static before any entity is to make that entity a class entity. It means that adding static before methods and variables make them class methods and class variables respectively, instead of instance methods and instance variables.
Hence, static methods and variables can be directly accessed with the help of Class, which means that there is no need to create objects in order to access static methods or variables.
+ 1
Static uses much less memory than instance as creating objects is not necessary to invoke and it gets into action without even instantiating an object .Thus it increases performance at certain scenarios .
Static also starts into action even before main method .so some of important things like connecting to jdbc database (making connection) ,or some specific process which should start at first even before main method , static method should be used
for example
class Example
{
static
{
System.out.print("hello"); //any other important things to load into jvm before main to execute
}
public static void main(String[] arg)
{
System.out.print("world");
}
op : helloworld
0
Could you please explain with example!!
0
For example you want to do something in one class that you won't create an object of that class to reach it . More explanation?
0
U told that by using static we get access from out of that class but public also does the same right!
0
If u dont specify a member of one class as static , then you have to create an object from that class as usual to get it . But with static members you won't create an object while using it . For example
Class person {
Static int age ;
}
When you want to use it just use this
Person.age
0
Ok thank you..!
0
But if
Class person {
int age ;
}
For using and getting acces to it in your program
Person p = new person();
Console.writeline(P.age);
0
Access any member of class of course . That class member behaves independently from any created object
- 1
Ok if we want to access any class without creating object we use static keyword am I correct