The text i am referring to is on kindle edition of JAVA SE 8 OCAJP-I book in the first chapter. I have do not have any soft copy of that...
krishnadhar Mellacheruvu wrote:variables like int,string etc hold values which change and we can also have types of those fields aka variables which can be given access modifiers and some types of variables have default values as well. But i am still failing to understand what exactly does the statement mean.
Me too, because I doubt that it actually said what you wrote.
First of all, "int, string [which should actually be String] etc" are NOT variables, they're types.
Secondly, String values don't change, because String is immutable.
Now I don't want to swamp you with terminology here, but it is really important that you understand the ones that the book is using.
In the declaration: "private String firstName;":
private String firstName = "a new first name";
firstName = "a different first name";
but if the declaration was:
private final String firstName;
you couldn't; and 'firstName' would then be a constant.
Now, getting back to your question: What exactly is it about the statement that you don't understand?
My advice would be to copy the statement (or paragraph) that's causing you problems, and and paste it here exactly as it appears in the book, and then ask your question again - maybe with a bit more detail about what it is you don't understand.
This is what is written in the book...
Java classes have two primary elements: methods, often called functions or procedures in other languages, and fields, or more generally known as variables. Together these are called members of the class. Variables hold the state of the program, and members operate on that state. If the change is important to remember, a variable stores that change.
The last sentence is what i did not get properly..
Does the STATE here means the values that the variables store... ?
Note that static fields do not actually form part of the object.
krishnadhar Mellacheruvu wrote:Does the STATE here means the values that the variables store... ?
Basically, yes. But as Campbell says, it usually refers to the current values of ALL variables that a class has collectively.
For example, the "state" of a ChessGame class would probably be the positions of all pieces currently on its 'board'.