Static and non-static
-> Static Variable have only one memory allocation and its accessed by all objects.
-> we no need to create object for this static variable. we can diecrtly assign the value for static variable using class name. and we can use that ny using object name
Ex:
Public class example
{
int a;
static string str;
Public static void funct()
{
System.out.printl("Arunraj");
}
}
Public class example2 {
Public static void main(String aargs[])
{
example.str="Selenium"
example.funct();
example obj= new example()
obj.a=10
System.out.println(obj.a)
System.out.println(obj.str)
example obj1= new example()
example.str="Selenium"
obj1.a=10
System.out.println(obj1.a)
System.out.println(obj1.str)
}
-> Static Variable have only one memory allocation and its accessed by all objects.
-> we no need to create object for this static variable. we can diecrtly assign the value for static variable using class name. and we can use that ny using object name
Ex:
Public class example
{
int a;
static string str;
Public static void funct()
{
System.out.printl("Arunraj");
}
}
Public class example2 {
Public static void main(String aargs[])
{
example.str="Selenium"
example.funct();
example obj= new example()
obj.a=10
System.out.println(obj.a)
System.out.println(obj.str)
example obj1= new example()
example.str="Selenium"
obj1.a=10
System.out.println(obj1.a)
System.out.println(obj1.str)
}
No comments:
Post a Comment