What is a Class?
A class is a templete definition (blueprint)
It defines the data contained in objects that are members of a class
It defines the methods (operations) that can be performed on those data
Constructors
To instantiate a new instance (object), invoke a constructor of the class using the new operator
- e.g. AddressBookEntry abe = new AddressBookEntry();
Must have the same name as the class itself
- File name, Public Class name, and Constructor Name should be the same
The Default Constructor
- If no constructors are explicitly defined in class, a public no-arg constructor with an empty body is implicitly defined in the class
Accessing via Reference Variables
Newly created instances (objects) are allocated in the memory
- They can be accessed via reference variables
Instance variables are "field" in an object
- e.g. kevin.firstName = "Kevin";
Instance variables vs. Local variables
Instance variables are fields that are unique to each instance of a class
- e.g. terry's first name is different from jeff's first name
Local variables are within methods
- Visible only to the method it is declared
- Not accessible from the rest of the class
Inheritance
A class (subclass) can extend a class (superclass)
- Subclass inherits accessible fields and methods from the superclass
- Subclass may add more fields
- Subclass may add more methods
- Subclass may override some methods of Superclass
Super keyword
Can be used to call superclass method
- To refer to print() method inherited from SuperClass (AddressBookEntry) in SubClass, SubClass (MyEntry) must use a qualified name using super keyword
Integrated Development Environment
- Source-code, syntax-directed editor
- Incremental complier
- Repository-based environment for code
- Project-based development
- Integrated debugging
- Support for team development
- Tools to facilitate specific programming models (Applets, Servlets, EJBs, Stored Procedures, XML, …)
Sample Final Exam Question
What is object-oriented programming?
Write programs using objects
- Objects that specify their (internal) data
- Objects that specify the methods by which you can manipulate their data