TommyWillB
Registered
I've recently started trying for the 3rd time to master some basic Java... So I bought a fairly straightforward Java 1.5 book that actually has some Mac OS X support.
I'm using Eclipse as my IDE and the vanilla Java 1.4.2 that's native on OS X 10.3.9.
I'm stuck on what seems like a very basic example of using other java classes/objects as fields/variables withing a class. Here is the code that I copied from the book:
The error I am getting is this
So I'm not sure if the book is wrong, or this is a Java 1.5 construct, or if I'm doing something boneheadedly stupid.
(The book insists that its okay to have both classes in the same .java/.class file... I tried it seperated, but I don't think I know how to make 2 classes talk [import?] to each other yet...)
Help?
I'm using Eclipse as my IDE and the vanilla Java 1.4.2 that's native on OS X 10.3.9.
I'm stuck on what seems like a very basic example of using other java classes/objects as fields/variables withing a class. Here is the code that I copied from the book:
Code:
package net.javagarage;
/**
* @author tommywillb
* <br />
* May 19, 2005
* <br />
* net.javagarage/PersonWithAddress.java
* <br />
*/
public class PersonWithAddress {
public String name;
public int age;
// Address is a class
public Address address;
public static void main(String[] args) {
Person person = new Person();
person.name = "Tommy W";
person.age = 32;
person.address = new Address();
person.address.street = "1 Private Address";
person.address.city = "San Francisco";
person.address.state = "California";
System.out.println("The person named " + person.name + " is aged " + person.age);
System.out.println("\r\r" + person.name + " lives in " + person.address.city);
}
}
class Address {
public String street;
public String city;
public String state;
}
Code:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
person.address cannot be resolved or is not a field
person.address cannot be resolved or is not a field
person.address cannot be resolved or is not a field
person.address cannot be resolved or is not a field
person.address cannot be resolved or is not a field
at net.javagarage.PersonWithAddress.main(PersonWithAddress.java:26)
So I'm not sure if the book is wrong, or this is a Java 1.5 construct, or if I'm doing something boneheadedly stupid.
(The book insists that its okay to have both classes in the same .java/.class file... I tried it seperated, but I don't think I know how to make 2 classes talk [import?] to each other yet...)
Help?