天天看点

2021-01-05 java-oop考前知识整理

类、对象,抽象类、封装、继承、多态、动态绑定,覆盖、重载,接口,异常处理、事件驱动编程

Class:

  1. Class are constructs that define objects of the same type;
  2. Class contains {variables / constructor / method}

Object:

  1. State and behaviour

Constructor

  1. Constructors are a special kind of methods that are invoked to construct objects.
  2. Constructor plays the role of initializing objects.
  3. 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:

  1. An abstract method can not be contained in nonabstract class.
  2. Class abstraction means to separate class implementation form the use of the class.

Encapsulation:

  1. 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:

  1. Avoid redundancy of the classes with many common features.
  2. The superclass’s constructor can’t be inherited. They are invoked explicitly or implicitly.

Polymorphism:

  1. An object of a subtype can be used wherever its supertype value is required.
  2. Casting: be used to convert an object of one class type to another within an inheritance hierarchy.
  3. Casting from superclass to subclass: explicit casting, may not always succeed.
  4. 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:

  1. An interface is a class-like construct that contains only constants and abstract methods.
  2.  The intent of an interface is to specify common behavior for objects.(comparable cloneable edible )
  3. All data fields are public static final and all methods are public abstract in an interface.

Exception handling:

  1. Try-catch
  2. Throws-throw
  3. 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.