| Author |
Objects and Constructs.
|
Gustavo Siqueira
Ranch Hand
Joined: Jun 15, 2011
Posts: 94
|
|
Hi the all!
See code: http://codepaste.net/u6x9vz
I with difficult for understand the question of acess objects of others class.
See here:
Because was given the access private ? And no public ?
Thanks you!
|
 |
Greg Charles
Bartender
Joined: Oct 01, 2001
Posts: 2536
|
|
|
Are you asking why checkDay() is a private method? It checks that you've given the constructor a valid day of the month and prints out an error message if you haven't. Nothing is supposed to call that method from outside the class, so they made it private.
|
 |
Gustavo Siqueira
Ranch Hand
Joined: Jun 15, 2011
Posts: 94
|
|
Hm..Ok. Thanks you!
Now, the that was done here ?
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12909
|
|
What do you mean with "the that is done here"?
private works per class, not per object. So a method in a class can access the private variables of any instance of the class.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Gustavo Siqueira
Ranch Hand
Joined: Jun 15, 2011
Posts: 94
|
|
|
One example please ?
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
Jesper de Jong wrote:What do you mean with "the that is done here"?
I think that's a bad translation from Portuguese, and something like "that which is done here" would be better.
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12909
|
|
An example of "private works per class":
Note that in line 9, the method can not only access the name variable of the current object, it can also access the name variable of another Example object (the one that e refers to).
Sometimes new Java programmers are confused by this. I thought that might be your question. If that was not what you were asking about, then please explain exactly what your question is.
|
 |
Gustavo Siqueira
Ranch Hand
Joined: Jun 15, 2011
Posts: 94
|
|
Hello Jasper!
No is the question.
Here.
The that was done ?
Set itself birthDate of type Date ? How so ?
Thanks you!
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
Gustavo, I really think you need a better Portuguese-to-English translator. It is impossible for an English-speaker (like me, for example) to understand your questions.
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12909
|
|
I don't understand what you mean with "the that was done".
In those two lines, two private member variables are declared of type Date. Since you don't initialize them, they will be initialized to the default value which is null.
See Declaring Member Variables in Oracle's Java Tutorials.
|
 |
Gustavo Siqueira
Ranch Hand
Joined: Jun 15, 2011
Posts: 94
|
|
Hello all!
First want apologize for not informing clearly into doubt.
The question this in that code, see:
Note: I am Brazilian! I am learning English.
Sorry by disorder!
Here code:
I know declaration variable string, int and derivates. But, in that case, no this declaration the variable birthDate how String ou int.
The variable this declared how Date. By which reason ?
Note: I no using the class Date of Java (import java.util.Date).
Note: Please sorry by my language.
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12909
|
|
So, is your question why these variables are of type Date and not String, int or something else?
Well, if you want to store things like a birth date or hire date then the data type Date seems a more appropriate choice to me than String, int or something else.
Variables can be of any type you want, there is no reason why it should always be String or int or something like that.
|
 |
Gustavo Siqueira
Ranch Hand
Joined: Jun 15, 2011
Posts: 94
|
|
Very good!
Thanks by response!
But, int that case he create the type Date for store the that ?
How do I for store in variable ?
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12909
|
|
It is hard to understand what exactly you are asking...
birthDate and hireDate are variables. The type of these variables is Date.
What exactly do you find confusing about that? It is not different from other variables that have type String or any other type.
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9946
|
|
I'll take a stab...
Java has tons of pre-defined classes. You are not limited to Strings, Integers and Floats. Some day, look at the java API (the java 6.0 API is here).
So, this code uses one of these other pre-defined classes call "Date". You can search that API page and see its constructors and other methods you can call on any Date object.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32651
|
|
fred rosenberger wrote: . . . So, this code uses one of these other pre-defined classes call "Date". . .
There are two classes called Date I think you want this one.
|
 |
 |
|
|
subject: Objects and Constructs.
|
|
|