java tutorial

java tutorial

Java Key Word

Static- Keywords

Static keywords in JAVA comprises variables, nested class, block or methods basically used for memory management. Keywords defined as static ones only belongs to the class.

//Program of static variable  

class Member8{  
   int student_rollno;  
   String last_name;  
   static String college ="ITS";  

   Student8(int r,String n){  
   student_rollno = r;  
   last_name = n;  
   }  
 void display (){
System.out.println(student_rollno+" "+last_name+" "+college);
}  

 public static void main(String args[]){  
 Member8 s1 = new Member8(111,"Karan");  
 Member8 s2 = new Member8(222,"Aryan");  
 s1.display();  
 s2.display();  
 }  
}

output – 111 Karan ITS
222 Aryan ITS


What is Constructors in java?

Constructors are the special type of functions mainly for initializing an object. It is invoked when an object is created. It is defined on the name of class and does not have any explicit return type.

For Example:

class Choco{  
	Choco(){System.out.println(" Choco is created");}  
	public static void main(String args[]){  
	Choco b=new Choco();  
	}  
	} 
Output: Bike is created

This Key Word

For referring current object, This keyword is used in JAVA. Following are some key uses of this keyword:

• To refer variable of the current class instance

• To implicitly invoke method if the current class

• this() can also be considered for invoking constructor of the current class

Super Key Word

The super keyword is a reference variable mainly referring to the immediate parent class object.

Leave a Reply

Your email address will not be published. Required fields are marked *