Slides OOP Part 1 Inheritance Introduction to Classes and Objects
Slides OOP Part 1 Inheritance Introduction to Classes and Objects
Class-based programming starts with classes which become the blueprints for
objects.
But what does this really mean?
To start, we need to understand what objects are.
They're really the key to understanding this object-oriented terminology.
What I'd like you to do is just have a look around in the area you're sitting in right now.
And if you do that, you'll find that there's many examples of real-world objects.
For example, I'm sitting here, and I can see:
• A computer.
• I can see a keyboard.
• I can see a microphone.
• I can see shelves on the wall.
• I can see a door.
These are characteristics about the item that can describe it.
I could also describe animate objects like people, or animals, or even insects like an
ant.
For an ant, the state might be:
• The age.
• The number of legs.
• The conscious state.
• Whether the ant is sleeping or is awake.
In addition to state, objects may also have behavior or actions that can be
performed by the object, or upon the object.
Behavior, for a computer, might be things like:
• Booting up.
• Shutting down.
• Beeping or outputting some form of sound.
• Drawing something on the screen, and so on.
If a field is not static, it's called an instance field, and each object may have a
different value stored for this field.
A static method can't be dependent on any one object's state, so it can't reference
any instance members.
In other words, any method that operates on instance fields needs to be non-static.
Classes can be organized into logical groupings which are called packages.
You declare a package name in the class using the package statement.
If you don't declare a package, the class implicitly belongs to the default package.
A class is said to be a top-level class if it is defined in the source code file and not
enclosed in the code block of another class, type, or method.
A top-level class has only two valid access modifier options: public or none.
Access
Description
keyword
public public means any other class in any package can access this class.
When the modifier is omitted, this has special meaning, called package
access, meaning the class is accessible only to classes in the same
package.
private private means that no other class can access this member