answersLogoWhite

0

What is the use of static method?

Updated: 8/20/2019
User Avatar

Wiki User

11y ago

Best Answer

Static methods are not specific to each instance of a class. This allows you to have functions which return the same output for the same input for each instance of the class.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the use of static method?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why you use main method when you can use static method?

The main method is called by the jvm when your program is executed. The main method is a static method: public static void main(String[] args) {} A static method is method that can be run without instantiate the class (creating an object from it) The main method is a static method. No other static method could replace it's functionality. PS By static method do you mean static initialiser? I often use static initialisers instead of a main method, but in these cases you must still have a main method, albeit an empty one ie. public static void main(String[] args) {} Notice that the method has an empty body A main method must be used if you intend to accept parameters at run time from the jvm.


Can you refer non static method from static content in java?

Shortly, you can not.Different approaches are however available.1. Put your non static method in different class. Then call it from your static content by first instantiating the class.2. Make a duplicate static method for your non static method and use from your static content.


Can you refer static method from non static method in java?

Yes, it is possible to call a static method from a non-static method. However, it is not possible to call a non-static method from a static method without first having an instance to operate on.


What is Static method in programming?

A static method in java is also named a class method, because it does not need an instance (of his class) to be invoked. Static methods can't use instance variables (non static variables) or use the keywords 'this'. These methods receive all the information they need to complete his task from his parameters


Why do you use static key word in Java programming?

Static is a keyword,when u execute a method in class file loaded, execute the first this method..


Static method can use only static variable why?

A static method is a method that is a class method and is not attached to the object of that class. So if we use a non static variable of the class, it would most probably not have been initialized because no object could have been created for the class. Hence it would throw a null pointer exception. To avoid such an ambiguity, there is a restriction that static methods can use only static variables. This is to ensure that class methods can access only class variables both of which would get initialized simultaneously.


It is perfectly legal to any instance variable inside of a static method?

No. You will get compilation errors. The complier will complain that you are trying to access non static variables from inside a static method. A static method can access only static variables.


what is the difference between final and static keywords?

static: we can use the keyword static either to method or to a variable. when we declare to a method,(eg: public static void main(String args[]),we can use this method without any object. when we use to a variable,there will be only one instance of that variable irrespective of how many objects that get created of that class. Final: Usage of final to method or to a variable makes them as constant. It's value cannot be changed...


Can you declears static in a local variable in a method in java?

we cannot use the staic keyword inside the method... But we can use the final keyword inside the method....


Can static method can be overloaded or not?

Yes, a static method may be overloaded.


Tell about static method?

in java a method is said to be static if 'static 'keyword is used before the method name . foe ex.- static void show(){ ........ } this method has the following property-- 1. it can invoke only a static method. 2. it can't be reffered using keyword 'this','super'. 3.static method can access only a STATIC MEMBER VARIABLE or STATIC CLASS VARIABLE . 4. there should not be static & non static version of a nethod in a class . 5.static method can be used before the creation of d object of dt class.


Static method can be call object?

yes we can call a static method with object