Posts

Showing posts with the label Static keyword in Java

Static keyword in Java rcub

  static keyword in Java   static is a keyword it can be used with variables, methods and blocks. static data  or static variable:- If you declare any variable as static, it is known as a static variable.  the static variable can be used to refer to the common property of all objects .. The static variable gets memory only once in the class area at the time of class loading. Syntax :  static <data-type> <variable-name >; Advantages of static variable ---> it saves memory example : public class student { int rno; String name; static String college="Asp"; public student()//default { } public student( int r,String n) { rno=r; name=n; } public void display() {      System.out.println("roll no:"+rno);      System.out.println("name:"+name);      System.out.println("college   name:"+college); } public static void main(String args[]) { student s=new stud...