answersLogoWhite

Top Answer
User Avatar
Wiki User
Answered 2011-02-16 05:04:24

The static keyword associated with a method or a variable in java specifies that the entity belongs to the class and not any object instance of the same.

Static Methods

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();

Static Variables

The static modifier tells the system that this particular variable belongs to the class and does not belong to any specific instance of the same. The class will contain only one instance of the static variable irrespective of how many objects of the class you create.

123
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0
User Avatar

Your Answer

Still Have Questions?

Related Questions

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.


Can an abstract method be declared static in java?

No, Java will fail to compile: "illegal combination of modifiers: abstract and static"This is a rather odd error, since Java does allow you to override static methods.


Are static variables serialized in java?

No, static variables are not serialized.


Can you overwrite main function in java?

You can not overwrite a static method in Java,and 'main' is a static method.so,you can't overwrite the 'main'.


Why do you use static in java program?

Using on static keyword, we can write static methods and variables. In java static variables accessing class level, and coming to the static methods without creating the object we can access methods.


Are static variable created by giving keyword static in java?

yes bcoz static variables


Can java constructors be declared static?

No.


What does following statement mean in java public static void main String args?

That will declare the main method in Java. When you run a Java program, this is the method which will be called first. class AnyClass { public static void main(String[] args) { // execution code here } }


Can you overload static method in java?

yes you very can very much to be likely. here is example of overloading static method in Java: public static int size(Object o) public static int size(Collection c)


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.


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

Static variable gets initialized first and then the static block gets executed.


What is static member in java?

static member means the method's behaviour does not depend on the state of an object.


What is psvm in java?

public static void main


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


Why would you declare a class as static in Java?

Declaring an inner class as static tells Java to treat it like a top-level class instead of an inner class.


What is the difference between static and nonstatic member with example in java?

In the case of a non-static member - the most common case - each object has its own copy of the specified variable. When a member is declared as static, there is only one copy of the variable, no matter how many objects there are. Example in Java: int a; //non-static static int b; //static


What is the relationship between Java and HTML?

HTML is a Hyper Text Markup Language. It is a static language. We can use HTML to create static web pages but we need java to make it dynamic.


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.


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

difference between constant and static variables in java


Difference between static and non static constructor?

JavaThere is really no such thing as a static constructor in Java. The closest thing that comes to mind is a factory class, which calls a private constructor when a static method is called.class A {// This private constructor can't be called by any other class.private A() {}// Here is your "static" constructorpublic static A getInstance() {return new A();}}


What are the restriction on static functions in java?

Static Methods Can:Access only static variablesInvoke other static methods onlyStatic Methods cannot:Access Instance variablesInvoke instance or non-static methods


To declare a method as static?

When you first declare a method, you would just write the word "static" before the name and parameter(s) of the method. An example of this is the main method often used for programming with Java: " public static void main(String[] args)".


Is it possible to define a java static method inside a main method?

No. Java does not allow the declaration of methods within methods.


How do you uss static in java?

It is uss to define class and method of pogrom's.


Still have questions?