Powered by Blogger.

This keyword in Java



This keyword in Java


This Keyword in Java is generally used in java for refer current class object. Here we also discuss about why use this keyword in java.
This keyword in java

Some other uses of this keyword are;

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

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

Here this keyword used for refer current class object.

this keyword is used to return current Object

public Box area()
{
 return this;
}

this Keyword with Method

this keyword can also be used inside Methods to call another Method from same Class.

this Keyword with Constructor

this keyword can be used inside the constructor to call another overloaded constructor in the same Class. 



facebook
google-plus
twitter
pinterest

No comments :

Post a Comment

HTML Tutorial

images

About Sitesbay

This blog is related to Java Tutorial, C++ Tutorial, C Tutorial, Online Earning tips and more in very simple and easy way. Here i will try to give complete idea related to all new technology.

Java Tutorial

Java is Object oriented programming language, It is more secure and high performance language.

C++ Tutorial

C++ is also Object oriented programming language, It is more simple and easy to learn.

 
https://sitesbay.blogspot.com/?utm_medium=d2898efa59afcc0bc411921036e22b767ca37b09