My Anna

Indias Biggest Engineering Education Community Enriching Students Minds with Latest Placement Papers, Study Materials, Fresher Jobs and Free E Books

A Unit of Aim Clear Technologies Ltd.
Search Study Materials, Jobs, Placement Papers, Interview Tips, Training Videos & More

Advertise with us

Who is online



Post new topic Reply to topic  [ 2 posts ] 

mkalaiyarasan
As a Family
As a Family
User avatar

Joined:
Tue Aug 25, 2009 5:25 pm
Beans: 35
In Bank: 0
College: studied
Degree: BE
Department: cse
State: Tamilnadu
Fav Quote: cse
Position: Employee
 
#2
Thu Sep 03, 2009 7:10 am
Post subject: Shadowing field names and this Post
By making use of the this keyword, you can even use the same name for arguments to the constructor (or any other method) as you use for field names. For example,
class TwoDPoint {

double x;
double y;

TwoDPoint(double x, double y) {
this.x = x;
this.y = y;
}

String getAsString() {
return "(" + this.x + "," + this.y + ")";
}

void setX(double x) {
this.x = x;
}

void setY(double y) {
this.y = y;
}

double getX() {
return this.x;
}

double getY() {
return this.y;
}

}
Inside a method, a declaration of a variable or argument with the same name as a field shadows the field. You can refer to the field by prefixing its name with this.

Profile E-mail
Offline

Kumari
lecturer
lecturer
User avatar

Joined:
Fri Sep 04, 2009 6:01 pm
Beans: 33
Location: India
In Bank: 50
College: Vaishnav
Degree: M.E
Department: Mech
State: Kerala
Position: Lecturer
 
#2
Thu Sep 17, 2009 6:43 am
Post subject: Re: Shadowing field names and this Post
Thanks kalaiarasu.
_________________
Image
Stranger: Mayre pass Car hey, Jwellery hey, Bank Balance Hey thumari pass kya hey? :yahoo:
Kumari: May re pass Anna he hey :useful:


Profile E-mail
Offline

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 
Bookmark & Share

Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB Group.

phpBB SEO