Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

this keyword in java

/**
 * This keyword,
 * this keyword is a reference variable that refers to the current class
 * instance.
 */
class Student {
    int id;
    String name;

    Student(int id, String name) {
        this.id = id;
        this.name = name;
    }

    void display() {
        System.out.println(this.id);// both way can call
        System.out.println(this.name);
        System.out.println(id);
        System.out.println(name);
    }
}

public class This {
    public static void main(String[] args) {
        Student student = new Student(10, "Mike");
        student.display();
    }
}
 
PREVIOUS NEXT
Tagged: #keyword #java
ADD COMMENT
Topic
Name
9+2 =