SCJP Certification

Sun Certified Java Programmer Certification exam essentials

September 1st, 2009

The this keyword

Java Facts, by Daisy Williams.

The this keyword refers to the currently executing instance of a class. It is commonly used to access members from within constructors, instance methods, and instance accessors. However, the static member functions do not have a this pointer. For example:

using System;
public class Students
{
public string name;
public string subcode;
//Constructor.
public Students(string name, string subcode)
{
//Use of this keyword to qualify members hidden by similar names.
this.name = name;
this.subcode = subcode;
}
}

The this keyword is used to pass an object as a parameter to other methods. For example:

Cal_Marks(this);

Share

Back Top

Responses to “The this keyword”

Comments (0) Trackbacks (0) Leave a comment Trackback url
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Your email address will not be published. Required fields are marked *

*