Java Fundamentals 6-Object oriented 1

Source: Internet
Author: User
Tags class definition type null

I. Definition of objects

Objects are entities in which things exist, often dividing objects into two parts: static and dynamic parts, static parts called properties, dynamic parts called behaviors, and understanding objects by exploring the properties of objects and observing the behavior of objects.

Two. Class

1. Class definition: A class of things with the same characteristics and behavior is called classes, which are the carriers of the properties and behaviors of encapsulated objects;

2. The main method of the class: the entry point of the class, which defines where the program starts and provides control over the flow of the program;

Format: public static void Main (string[] args) {

Method body

}

Features: no return value; static; formal parameter is an array;

3. Member method: Corresponds to the behavior of the class object. Also known as methods, dynamic properties. can have parameters. When the parameter is an object, the association relation between the classes is established;

Format: Permission modifier return value type (no return value write void) method name (argument type parameter name) {

Method body (Requires return value to use the return keyword)

}

4. Member variable: the property corresponding to the class object. Also known as properties, static properties. A member variable can be any type;

Format: Define the class first, and then define the member variables.

Permission modifier class class name (first letter uppercase) {

Permission modifier variable type variable name (you can set the initial value, if not set it will have a default value)

}

The initial value of the member variable:

BYTE 0
Short 0
int 0
Long 0L
Float 0.0F
Double 0.0D
Boolean false
Char '/u0000 '
Reference type NULL

5. Local variables: variables defined within the member method, created when the method is executed, destroyed at the end of the method execution, must be assigned or initialized when used, or a compilation error occurs.

6. Relationships between classes:

    • Association relationship: Ambiguous definition and weak relationship;
    • Inheritance relationship: What is a kind of what, in line with the logic can, the keyword extends;
    • Aggregation relationship: 1. Aggregation: not an essential part; 2. Combination: The combination of a class is essential;
    • Realize the relationship: just the result, regardless of the process;

7. How to better design a class: The appropriate method appears in the appropriate class.

Three. Object-oriented features:

1. Encapsulation: Is the core idea of object-oriented programming, encapsulates the behavior of the object's properties, and the class usually hides its implementation details from the customer, which is the idea of encapsulation; keywords: private/public;

2. Inheritance: The relationship between classes is called Association, inheritance is one of the associations, mainly take advantage of the common attributes between specific objects, the ancestor becomes the parent class, the subordinate becomes the subclass, the child class instance is the parent class instance, but cannot say that the parent class instance is the subclass the instance;

3. Polymorphism: The abstract class object is applied to subclasses;

Four. Creation of objects (also known as instantiation, created)

Format in Main method: Class Name Object name = new Object name ()

Java Fundamentals 6-Object oriented 1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.