类、对象,抽象类、封装、继承、多态、动态绑定,覆盖、重载,接口,异常处理、事件驱动编程
Class:
- Class are constructs that define objects of the same type;
- Class contains {variables / constructor / method}
Object:
- State and behaviour
Constructor
- Constructors are a special kind of methods that are invoked to construct objects.
- Constructor plays the role of initializing objects.
- 1. Constructor must have the same name as the class itself;
2. Constructor don’t have a return type---not even void;
3. Can be no-arg constructor
Abstract class:
- An abstract method can not be contained in nonabstract class.
- Class abstraction means to separate class implementation form the use of the class.
Encapsulation:
- The user of the class doesn’t need to know how the class is implemented. The details of implementation is encapsulated and hidden from the user.
Inheritance:
- Avoid redundancy of the classes with many common features.
- The superclass’s constructor can’t be inherited. They are invoked explicitly or implicitly.
Polymorphism:
- An object of a subtype can be used wherever its supertype value is required.
- Casting: be used to convert an object of one class type to another within an inheritance hierarchy.
- Casting from superclass to subclass: explicit casting, may not always succeed.
- Casting from subclass to superclass: always succeed. The special methods in subclass can’t be used anymore.
Dynamic binding:
The JVM dynamically binds the implementation of the method at runtime.
Overloading:
The ability to create multiple methods of the same name with different implementation.
Overriding:
Subclass to modify the implementation of a method defined in the superclass.
Interface:
- An interface is a class-like construct that contains only constants and abstract methods.
- The intent of an interface is to specify common behavior for objects.(comparable cloneable edible )
- All data fields are public static final and all methods are public abstract in an interface.
Exception handling:
- Try-catch
- Throws-throw
- Unchecked error: errors and runtime exception
Event-driven programming:
Timer / event / listener /
Key words:
Instance of: to test whether an object is an instance of a class.
This: is the name of a reference that refers to an object itself.
Extends:
Implements:
Equals(): used to determine whether 2 objects have the same references.
==: compares the contents of two objects.
Public: the class, data and methods are all visible to any class in any package.
Private: The data or methods can be only accessed by the declaring class.
Protected: data or method can be accessed by any class in the same package or its subclass.