Practice pieces
Inheritance: extension
This practice piece is all about extending classes.
Hints:
Start simple, with an empty Land
class that extends the Point class. Keeping everything in the Point class public, make an object in your main class
of this Land
class and try to access its x
and y
variables.
Then add a String landuse
variable to Land
, and check you can access that from the object.
Finally, change the Point class variables to private and check whether you can access them from the Land
object. Add accessor(get) and mutator(set) methods for x
and y
to Point
, making sure they're public, and try to use them via the Land
object.
If you need more help, here's the answers (or one option, anyhow).