answersLogoWhite

0

What should you make static in Java?

User Avatar

Anonymous

17y ago
Updated: 8/16/2019

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.

User Avatar

Wiki User

17y ago

What else can I help you with?

Related Questions

What are Static Imports in Java?

Static import is a java feature that introduced in Java 5. Static imports allow you to import static members of a class to be used without the class qualifier. And its also it should used in a moderate manner. If you overuse the static import feature, it can make your program unreadable and unmaintainable, polluting its namespace with all the static members you import. Source- Oracle documentation. Marcus Biel Clean Code Course


Static membors partispating Overwriting in java?

Static membors partispating in Overwriting in java?


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.


Are static variables serialized in java?

No, static variables are not serialized.


Are static variable created by giving keyword static in java?

yes bcoz static variables


What are static objects in java?

There is no separate entity as a static object in java. The static keyword in java is used to signify that the member (either a variable or a method) is not associated to an object instance of the class. It signifies the fact that the member belongs to the class as a whole. The words static and objects are opposites of one another so you cannot have a static object. However, you can declare an object as a class level variable which could be referred to as a static object but it will be referred to as a static or class variable and not a static object.


What is psvm in java?

public static void main


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 overload static methods in Java?

Yes you can overload the static method. But it should be avoided because memory to static methods are allocated at the time of class load.....so memory will be wasted if we don't use that methods. Whereas non-static method memory allocation depends on Object


Can an abstract method be declared static in java?

No you cant, any compiler I've ever used wont allow this. It would not make any sense to do this anyway. because the JVM directly accesses ur top class without instantiating it. Though for accessing the instance data members, the class must need to be instantiated.


WAP to show the difference between a variable and static variable?

difference between constant and static variables in java


Can you interchange the term public and static in java?

The two are different, and independent from one another. A variable can be public, static, both public and static, or neither.