answersLogoWhite

0

Static method can be call object?

Updated: 12/13/2022
User Avatar

Mohitkaushik

Lvl 1
15y ago

Best Answer

yes we can call a static method with object

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Static method can be call object?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can main method be non-static?

No, the reason is simple: A method marked as a static means, that you don't need create an instance (create an object with the 'new' operator) in order to use it. The main method is the entry point for a java application, therefor there is nothing after you call it. no one who can create an object of the type of your class and call the main method. So the jvm must call the main method with no object reference.


When does this pointer get created?

When we call non static method with respect to class object then this pointer is created which keep the reference of that object.


What is static java most commonly used for?

Static java method is the same as a static variable. They belong to a class and not an object of that class. If a method needs to be in a class, but not tied to an object, then one uses static java.


Do static methods operate on objects why?

No. Why? By definition. A static method is, precisely, a method that is not meant to operate on an object. It can only work with static fields, and other static methods, of its class.


When will you define a method as static in java?

Static keyword when used with a method, specifies that this method belongs to the class and not a particular instance of the class (a.k.a object of the class) Ex: public class StaticTest { public static String getAuthorName() { return "Anand"; } } Here getAuthorName is the static method and it can be accessed without instantiating an object of the class StaticTest. You can access this method as: String authorName = StaticTest.getAuthorName();

Related questions

Can main method be non-static?

No, the reason is simple: A method marked as a static means, that you don't need create an instance (create an object with the 'new' operator) in order to use it. The main method is the entry point for a java application, therefor there is nothing after you call it. no one who can create an object of the type of your class and call the main method. So the jvm must call the main method with no object reference.


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.


When does this pointer get created?

When we call non static method with respect to class object then this pointer is created which keep the reference of that object.


Why use static?

Static is a keyword which is used to call the methods or variables without creation of that class object. It will directly calls the respective method and varialbles.


What is need of static method?

If you need to access a method without creating an object of corresponding class, it need to be a static method.


Is it possible to call static methods with out creating object?

Yes, we can access all methods which declare with static means then we can access.. ex: class s{ static method() { System.out.println("Welcome"); } } class fun{ public static void main(String args[]) { method(); } }


What is static java most commonly used for?

Static java method is the same as a static variable. They belong to a class and not an object of that class. If a method needs to be in a class, but not tied to an object, then one uses static java.


Why main is static?

The main method is static because the JVM would be invoking this method as the starting point of execution. If this is like other normal methods, the JVM would have to instantiate an object of the class before it can call it. This is not possible because this is the starting point. If the main method is static the JVM can directly call this by specifying the class name.


Why static is used in main method?

It is declared static because the JVM would need to execute the main method and if it is not static the JVM would need an object of the class to access the method. How can the JVM get an object of a class without invoking it. since it is static, the JVM can easily access it without this need to have an object of the class.


Can the main method call the other method if it is not defined as static?

No


Do static methods operate on objects why?

No. Why? By definition. A static method is, precisely, a method that is not meant to operate on an object. It can only work with static fields, and other static methods, of its class.


How do you call static methods without using objects?

You can call a static method via an object; the other alternative is to use the class name. A common example is the following, to calculate the exponential function: Math.exp(x) Here, exp() is a static function in the class Math. Note that the class name is used instead of an object.