-
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
-
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.
-
Thanks for the quick response