This site requires JavaScript, please enable it in your browser!
Greenfoot back
Loopy
Loopy wrote ...

2012/5/11

Instance Variables

Loopy Loopy

2012/5/11

#
Can someone please help me to understand how to declare an instance variable? The books I've been reading have not been very helpful with what I am assuming they think is an easy concept so it is left out.
SPower SPower

2012/5/12

#
A instance variable is a variable, which you can use throughout all the (not class) methods. You just write private first (you can write public, but that's not so good programming), then the type and finally the name. This:
private int instanceVariable;
Write this at the top of the class:
public Class AClass
{
//instance variables here
//other code here
}
I hope this helps.
danpost danpost

2012/5/12

#
You really should review the Java trails; especially the ones on 'Getting Started' and 'Learning the Java Language'. They are listed in the second section (called 'Trails Covering the Basics') on the left at this site.
Loopy Loopy

2012/5/12

#
Thank you danpost. I was able to get my questions answered!
You need to login to post a reply.