• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Objects and Constructs.

 
Gustavo Siqueira
Ranch Hand
Posts: 97
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 2989
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 97
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm..Ok. Thanks you!
Now, the that was done here ?

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15459
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gustavo Siqueira
Ranch Hand
Posts: 97
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One example please ?
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15459
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 97
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jasper!
No is the question.

Here.



The that was done ?
Set itself birthDate of type Date ? How so ?
Thanks you!
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15459
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 97
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15459
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 97
C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15459
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12188
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49862
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic