Breaking News
yeni film izle hd film seyret film izle

this keyword in java use of this keyword in java

this keyword

  • this keyword is used to refer to current object.
  • this is always a reference to the object on which method was invoked.
  • this can be used to invoke current class constructor.
  • this can be passed as an argument to another method.

Example :

class Box
  Double width, weight, dept; 
  Box (double w, double h, double d)
   this.width = w;
   this.height = h;
   this.depth = d;

Here the this is used to initialize member of current object.

The this is used to call overloaded constructor in java

class Car
 private String name;
 public Car()
  this("BMW");    //oveloaded constructor is called.
 public Car(Stting n)
 {;   //member is initialized using this.

The this is also used to call Method of that class.

public void getName()

public void display()

this is used to return current Object

public Car getCar()
 return this;

Check Also

Exception Handling In Java

Exception Handling is the mechanism to handle runtime malfunctions. We need to handle such exceptions …