What is static variable and static method?
Answer Posted / nithya
Static Variable:
A variable that can be accessed by any class.
Eg:
class Add
{
static int a; // Defaultly the value of a is 0 since,it
is declared as static.
}
class Sub
{
int A=Add.a; // the value of A is 0.
}
Static Method:
if the method is declared as Static then its variable
should be also declared as static and static method can be
accessed with the help of class name rather than object name
eg:
class Addition
{
public static void Add()
{
}
}
class Subraction
{
Addition.Add();
}
Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
What is the difference between the jdk 1.02 event model and the event-delegation model introduced with jdk 1.1?
public class Test { public static void main(String[] args) { int countA = 0; int countB = 0; int countC = 0; int countD = 0; int countE = 0; int countF = 0; int countG = 0; int countH = 0; int countI = 0; int countJ = 0; int countK = 0; int countL = 0; int countM = 0; int countN = 0; int countO = 0; int countP = 0; int countQ = 0; int countR = 0; int countS = 0; int countT = 0; int countU = 0; int countV = 0; int countW = 0; int countX = 0; int countY = 0; int countZ = 0; } } Can anybody tell me any alternate solution(like loop or something) to automate this initialization process. Ex:- for(char chr='A';chr<='Z'; chr++) { (int) String "count"+chr = 0; }
Can memory leak in java?
Can we force the garbage collection to run?
How many digits is int32?
Can we override constructor?
What are accessor methods in java?
How do you check if a string is lexicographically in java?
What is java util?
What are the Static and Dynamic Variables? Differentiate them.
Why java does not support pointers?
What is regex java?
Tell me about different OOPS concepts.
Can we overload destructor in java?
What are peerless components in java programming?