TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Tuesday, 7 April 2020

This Keyword In Java | Static and This Keyword In Java | This Keyword In Hindi

This keyword in java

There can be a lot of usage of java this keyword. In java, this is a reference variable that refers to the current object.
Using in java this keyword
Fig: This Keyword In java

Usage of java this keyword

Here is given the 6 usage of java this keyword.

1.    this can be used to refer current class instance variable.
2.    this can be used to invoke current class method (implicitly)
3.    this() can be used to invoke current class constructor.
4.    this can be passed as an argument in the method call.
5.    this can be passed as argument in the constructor call.
6.    this can be used to return the current class instance from the method.
static and this keyword in java
Fig: Use Of This Keyword In java

Example:

   class Student{  
   int rollno;  
   String name;  
   float fee;  
   Student(int rollno,String name,float fee){  
   this.rollno=rollno;  
   this.name=name;  
   this.fee=fee;  
    }  
   void display(){System.out.println(rollno+" "+name+" "+fee);}   
     }  
         
    class TestThis2{    
    public static void main(String args[]){  
   Student s1=new Student(111,"ankit",5000f);  
   Student s2=new Student(112,"sumit",6000f);  
s  1.display();  
s  2.display();  
    }
    }  

Output:

111 ankit 5000
112 sumit 6000


No comments:

Post a Comment