Results 1 to 4 of 4
Thread: what does "this" mean?
- 07-31-2007, 05:21 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 41
- Rep Power
- 0
- 07-31-2007, 05:57 PM #2
Member
- Join Date
- Jul 2007
- Posts
- 74
- Rep Power
- 0
Hi,
"this" means you indicates the variable or instance which is used by this[Present] class. Suppose your base class have int x, and derived class also have int x then you need to use this key word to point out the derived class's
x. .....
- 08-01-2007, 04:38 AM #3
Member
- Join Date
- Aug 2007
- Posts
- 15
- Rep Power
- 0
Hi there, let me give you an example of "this" that will help you grasp this concept better. Assume you have a class, called Dog. The Dog has three variables, age, height and weight. And you have a constructor:
public class Dog
{
int age;
int height;
int weight;
public Dog(int age, int height, int weight)
//Constructor. The calling method will parse int age, height and weight
{
/*
So this is the problem. both variables have the same name! age that is passed in and age that is the class variable! so to solve it, you use "this"*/
this.age=age;
this.height=height;
this.weight=weight;
}
}
So in the three lines of "this.age" "this.height" and "this.weight". it sets the CLASS variable, the one declared in the lines right after the class declaration to the three integers that are passed in.
- 08-01-2007, 04:45 PM #4
Member
- Join Date
- Jul 2007
- Posts
- 41
- Rep Power
- 0
Similar Threads
-
Hwlp with "Open", "Save", "Save as..."
By trill in forum New To JavaReplies: 3Last Post: 11-02-2010, 09:26 AM -
failure at Class.forName("oracle.jdbc.driver.OracleDriver");
By RonNYC in forum EclipseReplies: 1Last Post: 03-14-2008, 02:51 PM -
Exception in thread "main" java.net.ConnectException: Connection timed out
By osval in forum Advanced JavaReplies: 1Last Post: 07-27-2007, 10:59 PM -
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
By romina in forum New To JavaReplies: 1Last Post: 07-25-2007, 10:55 PM -
ArrayList: Exception in thread "main" java.lang.NullPointerException
By susan in forum New To JavaReplies: 1Last Post: 07-16-2007, 06:32 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks