answersLogoWhite

0


Best Answer

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.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Do static methods operate on objects why?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can a static method access instance variables?

Variables cannot access variables; only methods can access variables. Non-static methods (also known as instance methods) are local to an object of the class and therefore have access to a "this" reference (referring to the current instance of the class, the object upon which the method was invoked), but static variables are local to the class itself. These variables are shared by all objects of the class and are therefore accessible to non-static methods. Static variable are also accessible to static methods and are therefore accessible even when no objects of the class exist.


Why keyword static is to include in main method?

A class may have both static and non-static methods. Non-static methods are local to objects of the class (instances of the class) and are often known as instance methods for that reason. Being local to an object means they can refer to the current instance of the class through the implicit "this" reference. Static methods, on the other hand, are local to the class and do not have an implicit "this" reference. As such, static methods can be invoked even when no instances of the class are in scope. Since the main function is the entry point of the application and there can be only one entry point, it doesn't make any sense to declare it an instance member because no objects of the class would physically exist.


What is the difference between a class method and an instance method?

Instance methods can be called by the object of a Class whereas static method are called by the Class. When objects of a Class are created, they have their own copy of instance methods and variables, stored in different memory locations. Static Methods and variables are shared among all the objects of the Class, stored in one fixed location in memory.Static methods cannotaccess instance variables or instance methods directly-they must use an object reference. Also, class methods cannot use the this keyword as there is no instance for this to refer to.


Can a method be static and synchronized?

Yes. In Java methods can be static and synchronized. Static methods access other static members in the class. Static in case of inheritance are treated as non - static. Synchronized methods are those which have dedicated thread attached to it and no other can access until currrent thread leaves the control from it.


Why you can not use this pointer in static functions?

Because this points to the current object, but static methods don't have a current object (actually this is definition of the static methods).

Related questions

How do you access the static variable and static methods of a class?

In java we access static variables and static methods without creating objects. i.e.,we can access directly by using classname we can also access static variables and static methods by using objects which are created by using class where the static variables and static methods are available


Can a static method access instance variables?

Variables cannot access variables; only methods can access variables. Non-static methods (also known as instance methods) are local to an object of the class and therefore have access to a "this" reference (referring to the current instance of the class, the object upon which the method was invoked), but static variables are local to the class itself. These variables are shared by all objects of the class and are therefore accessible to non-static methods. Static variable are also accessible to static methods and are therefore accessible even when no objects of the class exist.


Why keyword static is to include in main method?

A class may have both static and non-static methods. Non-static methods are local to objects of the class (instances of the class) and are often known as instance methods for that reason. Being local to an object means they can refer to the current instance of the class through the implicit "this" reference. Static methods, on the other hand, are local to the class and do not have an implicit "this" reference. As such, static methods can be invoked even when no instances of the class are in scope. Since the main function is the entry point of the application and there can be only one entry point, it doesn't make any sense to declare it an instance member because no objects of the class would physically exist.


Does static electricity affect objects?

Yes, static electricity does affect objects.


What is the difference between a class method and an instance method?

Instance methods can be called by the object of a Class whereas static method are called by the Class. When objects of a Class are created, they have their own copy of instance methods and variables, stored in different memory locations. Static Methods and variables are shared among all the objects of the Class, stored in one fixed location in memory.Static methods cannotaccess instance variables or instance methods directly-they must use an object reference. Also, class methods cannot use the this keyword as there is no instance for this to refer to.


Can a method be static and synchronized?

Yes. In Java methods can be static and synchronized. Static methods access other static members in the class. Static in case of inheritance are treated as non - static. Synchronized methods are those which have dedicated thread attached to it and no other can access until currrent thread leaves the control from it.


Why you can not use this pointer in static functions?

Because this points to the current object, but static methods don't have a current object (actually this is definition of the static methods).


What makes the use of static methods easy to understand?

There are many factors that contribute to the easy to understand nature of static methods. If one were to look in a dictionary, the definition of static is that it is constant. Thus in turn, this makes static methods easier to comprehend.


Can non static methods can access static variables?

Yes, they can


What should you make static in Java?

Static keyword signals something that is shared among all objects of the same class: i.e. a variable that all objects of the class can reference to, or method that all objects of the class can access. Usually, class constants are made static since it is the same in all objects of the same class thus it saves space not having to have variables for the same data for each class. But usually private instances should not be made static since it creates some strange situations, i.e. if you modify the data of one object, the data of the other object of the same class is also changed. Statics methods are common in main classes, in fact the main method itself is static, meaning it does not need a object to call it. The helper methods in a main class is usually static, since main classes are non-instantiable.


Which one executed first static block or static methods in java?

Static Blocks are always executed first. A static block is executed when your class is charged but a static method is executed only when is called, therefor first the class is charged and then is executed a method.


Can an abstract method be declared static?

Yes. Abstract methods can be declared static