I don't understand the interface code below. Specifically, the methods inside the interface. How can you make a method of a class? I'm not really grasping the "public Address" and "public PhoneNumber" part. Can someone please explain why this is done and what is the advantage....
I guess I'm having difficulty to conceptualize what it would return exactly. I understand if it returns a String or an int or boolean.....but I'm having difficulty conceptualizing the Address object that it would return. Does that mean that it would have values for the address fields (i.e. values for street, city, region, etc)?
you can see what it would have in the code you posted. The Address class is defined to have four strings: street, city, region, and postalCode.
you can then call the methods you define:
Note that you have the Address class defined as abstract, although I'm not sure why. Normally, an abstract class would have one or more methods declared but not implemented. In your Address class, they all appear to be implemented.
If this is supposed to be an abstract class, then you would need some other concrete (i.e. non-abstract) class that extends it. That sub-class would be BOTH an Address and a (whatever you named the concrete class) in the same way a dog is both a Mammal and a Dog.
You can assign that returned object to any legal reference - and an Address reference certainly works.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop