Example for class variable and instance variable in java
Answers
Answered by
2
Hey!
Example of class variable :-
public class student
{
static int n = 40;
public static void display()
{
System.out.println(n);
}
}
Here static int n = 40 is the class variable.
Example for instance variable :-
class student
{
int m = 40;
void disp()
{
System.out.println(m);
}
}
Here, int m = 40 is the instance variable.
Hope it helps^^
Example of class variable :-
public class student
{
static int n = 40;
public static void display()
{
System.out.println(n);
}
}
Here static int n = 40 is the class variable.
Example for instance variable :-
class student
{
int m = 40;
void disp()
{
System.out.println(m);
}
}
Here, int m = 40 is the instance variable.
Hope it helps^^
Similar questions