1. Exam Points
- Identify
attributes(instance variables) andbehaviors(methods).- Identify the correct
data typesforinstancevariables.- Identify a
classand aninstance.
2. Knowledge Points
(1) Class and Object
- A
classdefines common attributes and behaviors of objects. - An
objectis a specific instance of a class with defined attributes. - Example:
- Student is a class
- Xiaoming is an object/instance of the Student class
Attributesrefer to the data related to the class and are stored in variables.Behaviorsrefer to what instances of the class can do (or what can be done with them) and are defined by methods.- Example:
public class Dog{ private String name; private int age; public void bark(){} public void bite(){} } // here is a code segment in another class Dog d1 = new Dog(); Dog d2 = new Dog();In this example:- Dog is a class
- d1, d2 are two objects/instances of the Dog class.
- name and age are instance variables(实例变量), representing attributes of Dog objects.
- bark and bite are methods (方法), representing behaviors of Dog objects.
(2) Libraries and APIs
- Libraries are collections of classes.
- Classes are grouped into packages.
- An application programming interface (API) specification informs the programmer how to use those classes.
- Documentation found in API specifications is essential to understanding the attributes and behaviors of a class defined by the API.