Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-29-2009, 10:55 AM
rrp rrp is offline
Member
 
Join Date: Dec 2007
Posts: 3
Rep Power: 0
rrp is on a distinguished road
Default Member Variables
I am sure this is a simple question.

I have 2 simple classes

One called package1.Date
and one called package2.DateFormater

In Date I have 3 member variables. day,month and year - all int.

If I include and instantiate Date in the DateFormatter class and try and set the member variables it doesn't like it.

However if I put DateFormater in the same package it is fine.

Help???

Robert
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-29-2009, 11:50 AM
Senior Member
 
Join Date: Sep 2008
Location: Voorschoten, the Netherlands
Posts: 1,269
Rep Power: 3
JosAH is on a distinguished road
Default
If one object is defined in one package and another object in another package the members of those objects (to be accessible) have to be "public". If both classes are stored in the same package they can have their default access rights, i.e. package scope (no keyword for this necessary).

Code:
package p;

public class C {
   int x; // not reachable outside package p;
   public int y; // reachacble from everywhere
}
... alternatively you can define accessors and mutators (getters and setters) for those member variables. You can leave the member variables private and make those methods public.

kind regards,

Jos

ps. This should be all described in great detail in your textbook.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-29-2009, 12:25 PM
rrp rrp is offline
Member
 
Join Date: Dec 2007
Posts: 3
Rep Power: 0
rrp is on a distinguished road
Default
Thanks for the quick response
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What are Instance variables and static variables? sandeshforu New To Java 3 09-09-2009 06:48 PM
Greetings From New Member... palms_09@yahoo.com New To Java 0 01-09-2009 02:50 AM
Hello.Am a new Member winkodes Java Applets 0 12-07-2008 08:19 AM
new member-need help vandana New To Java 2 01-21-2008 07:01 AM
new member riadmazloum Introductions 1 08-09-2007 01:15 AM


All times are GMT +2. The time now is 11:18 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org