Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions static keyword
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package Sem4_JAVA;

class A
{
static int i=1; //static variable
static int j=2;
int k=1431;
static void B() //static method
{
System.out.println("i:"+i);
}
void C() //non static method
{
System.out.println("non static method");
System.out.println("non static variable:"+k);
}
}
public class StaticDemo {
static int m=100;
static int n;
static void callme()
{
System.out.println("inside static method");
System.out.println("m:"+m);
}
static //static block
{
System.out.println("block1");
}
static
{
System.out.println("block2");
n=m+100;
}
public static void main(String[] args) {
A obj=new A();
callme();
System.out.println("n:"+StaticDemo.n);
A.B(); //calling static method
System.out.println("j:"+A.j); //printing static variable
obj.C(); //to call non static method
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useful