java this keyword

In this tutorial, you will learn about this keyword in java programming.

You will learn what is this keyword, why it is used and how to use it, how to access the class members using this in detail with example.

Source code for this video tutorial

Code for Student.java

package oops;

public class Student {

  String name;
  int age;
  
  
  Student(){
   
  }
  
  Student(String name){
   this();
   this.name = name;
  }
  
  Student(int age){
   this("noname");
    this.age = age;
  }
  
  Student(String name, int age){
   this(age);
   System.out.println("Constructor with 2 parameters");
  }
  
  
  
  void introduce(){
   
   System.out.println("name is "+this.name+" and age is "+this.age);
  }
 
  static void howManyStudents(){
   //this
  }
}

Code for Tutorials.java

package oops;

public class Tutorials {

 public static void main(String[] args) {
  
  Student anil = new Student("anil",24);
  
  anil.introduce();
 }
}
Back To Top