adspace


What is static variable and static method?

Answer Posted / nagina

static variable:
It is a variable which belongs to the class and not to
object(instance).Static variables are initialized only
once , at the start of the execution . These variables will
be initialized first, before the initialization of any
instance variables. A single copy to be shared by all
instances of the class. A static variable can be accessed
directly by the class name and doesn’t need any object
Syntax : <class-name>.<variable-name>
static method:
It is a method which belongs to the class and not to
the object(instance). A static method can access only
static data. It can not access non-static data (instance
variables). A static method can call only other static
methods and can not call a non-static method from it.
A static method can be accessed directly by the class name
and doesn’t need any object
Syntax : <class-name>.<method-name>
A static method cannot refer to "this" or "super" keywords
in anyway

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a classloader in java?

1086


Write a program to find the whether a number is an Armstrong number or not?

1096


How to create a base64 decoder in java8?

1135


Write a program to print count of empty strings in java 8?

1084


Explain public static void main(string args[]) in java.

1074


What are the differences between heap and stack memory in java?

1135


What is java string pool?

1080


What is a constructor overloading in java?

1124


explain different ways of using thread? : Java thread

1080


Differentiate between static and non-static methods in java.

1126


What is the difference between break and continue statements?

1124


Write a java program to find the route that connects between Red and Green Cells. General Rules for traversal 1. You can traverse from one cell to another vertically, horizontally or diagonally. 2. You cannot traverse through Black cells. 3. There should be only one Red and Green cell and at least one of each should be present. Otherwise the array is invalid. 4. You cannot revisit a cell that you have already traversed. 5. The maze need not be in the same as given in the above example

2662


What is the difference between equals() and == in java?

1037


How to sort array in descending order in java?

994


What is parsing in java?

1039