0

What does static mean?

4th Jun 2020, 6:33 AM
Priyanka Macha
Priyanka Macha - avatar
11 Answers
+ 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
4th Jun 2020, 6:44 AM
hossein sadeghi
hossein sadeghi - avatar
+ 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.
4th Jun 2020, 6:57 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 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
5th Jun 2020, 5:26 PM
Agilesh
Agilesh - avatar
0
Could you please explain with example!!
4th Jun 2020, 6:54 AM
Priyanka Macha
Priyanka Macha - avatar
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?
4th Jun 2020, 7:00 AM
hossein sadeghi
hossein sadeghi - avatar
0
U told that by using static we get access from out of that class but public also does the same right!
4th Jun 2020, 7:03 AM
Priyanka Macha
Priyanka Macha - avatar
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
4th Jun 2020, 7:08 AM
hossein sadeghi
hossein sadeghi - avatar
0
Ok thank you..!
4th Jun 2020, 7:10 AM
Priyanka Macha
Priyanka Macha - avatar
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);
4th Jun 2020, 7:11 AM
hossein sadeghi
hossein sadeghi - avatar
0
Access any member of class of course . That class member behaves independently from any created object
4th Jun 2020, 7:15 AM
hossein sadeghi
hossein sadeghi - avatar
- 1
Ok if we want to access any class without creating object we use static keyword am I correct
4th Jun 2020, 7:13 AM
Priyanka Macha
Priyanka Macha - avatar