Static keyword in Java
Static keyword in java is mainly used for memory management. In Java you can apply S
tatic Keyword with variables, methods, blocks and nested class.
class StaticDemo
{
int rollno;
String name;
static String college ="ITM";
StaticDemo(int r,String n)
{
rollno = r;
name = n;
}
void display ()
{
System.out.println(rollno+" "+name+" "+college);
}
public static void main(String args[])
{
StaticDemo obj1 = new StaticDemo(45,"Sultan");
Student8 obj2 = new StaticDemo(11,"Faiz");
obj1.display();
obj2.display();
}
}
Output:
45 Sultan ITM
11 Faiz ITM
No comments :
Post a Comment