Thursday 22 November 2012

STATIC KEYWORD

Fixed is coffee keyword and key phrase it is used for static varying static techniques static prevents and static inner sessions but not for the external category.

STATIC VARIABLES:-
Static varying could be identified &executed at enough time running the byte value of specific category. the value of varying is nor different for item to item then we should announce that varying as static.
In coffee program static varying will be used by either by using category name straight (or) by using specific category item referrals category item referrals varying.
EX:-
class A
{
int x=10;
static int y=20;
public static gap primary (string []args)
{
//system.out.println(A.x);//compile time error
system.out.println(a.y);//20
A a=new A();
System.out.println(a.y);//20
System.out.println(a.x);//10
}
}

STATIC METHODS:-
Static technique will allow straight static different of the same category which will not allow non static varying straight if we want use non static techniques then we have to make the reactive category item with the produced referrals varying only in coffee program we are able to accessibility static techniques either by using category name straight (or) by using the specific group item referrals.
static techniques will not allow this keyword and key phrase but it is possible to accessibility static techniques with this keyword and key phrase.
class staticEX
{
int x=10;
static int y=20;
public static gap m1 ()
{
//system.out.println(x);//c.t.error
staticEX se =new staticEX();

system.ut.println(se.x);//10
ystem.out.println(y);//20
}
public gap m2()
{
this.m1();
}
}
class static test
{
public static gap primary (string[] args)
{
staticEX se =new static ();
se.m1();
se.m2();
stasticEX.m1();
}
}

OUTPUT:
javc statictest.java
JAVA STATIC TEST
10
20
10
20
10
20


STATIC BLOCK:
    It is coffee function which will be identified & implemented at enough duration of running the specific category byte value.static prevents will allow static varying straight it will not allow static factors.
Static prevents will not allow this keyword and key phrase.
Syntax:-
static
{
-----
}


STATIC-FOLWCONTROL:-
If we offer static factors static prevents with in only one category then they will be executed at enough duration of working byte value as per the exchange in which we offer.
EX:-
Class A{
static int m1()
{

system.out.println("static method");
return 0;
}
static{
system.out.println("staticblock");
}
static int i=m1();
}
class staticEX{
public static gap primary (string[] args)
{
   new A();
}
}

OUTPUT:-
Javc staticEX.java
Java staticEx
staticblock
staticmethod

No comments:

Post a Comment