aspose file tools*
The moose likes Java in General and the fly likes Objects and Constructs. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Objects and Constructs." Watch "Objects and Constructs." New topic
Author

Objects and Constructs.

Gustavo Siqueira
Ranch Hand

Joined: Jun 15, 2011
Posts: 97

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

Joined: Oct 01, 2001
Posts: 2854
    
  11

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: 97

Hm..Ok. Thanks you!
Now, the that was done here ?

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

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 8 API documentation
Gustavo Siqueira
Ranch Hand

Joined: Jun 15, 2011
Posts: 97

One example please ?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18657
    
    8

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

Joined: Aug 16, 2005
Posts: 14269
    
  21

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: 97

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: 18657
    
    8

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

Joined: Aug 16, 2005
Posts: 14269
    
  21

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: 97

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

Joined: Aug 16, 2005
Posts: 14269
    
  21

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: 97

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

Joined: Aug 16, 2005
Posts: 14269
    
  21

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: 11411
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
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.