Java Reference
In-Depth Information
So What Are Objects?
Anything can be thought of as an object. Objects are all around you. You can consider Tree to be a
particular class of objects: trees in general; although it is a rather abstract class as you would be hard
pushed to find an actual occurrence of a totally generic tree. Hence the Oak tree in my yard which I call
myOak , the Ash tree in your yard which you call thatDarnedTree , and a generalSherman, the
well-known redwood, are actual instances of specific types of tree, subclasses of Tree that in this case
happen to be Oak , Ash , and Redwood . Note how we drop into the jargon here - class is a term that
describes a specification for a collection of objects with common properties.
A class is a specification, or template - expressed as a piece of program code - which defines what goes
to make up a particular sort of object. A subclass is a class that inherits all the properties of the parent
class, but that also includes extra specialization. Of course, you will define a class specification to fit
what you want to do. There are no absolutes here. For my trivial problem, the specification of a Tree
class might just consist of its species and its height. If you are an arboriculturalist, then your problem
with trees may require a much more complex class, or more likely a set of classes, that involve a mass of
arboreal characteristics.
Every object that your program will use will have a corresponding class definition somewhere for
objects of that type. This is true in Java as well as in other object-oriented languages. The basic idea of a
class in programming parallels that of classifying things in the real world. It is a convenient and well-
defined way to group things together.
Generic Tree
derived from
derived from
derived from
Ash
Redwood
Create
instance
Create
instance
Oak
Objectsofaclass
will have a given set
of properties in common.
Each object of the class
will have its own values
for these properties.
Tree
Objects of
type Ash
myAsh
yourAsh
Search WWH ::




Custom Search