Java Object-Oriented foundation

Source: Internet
Author: User

1. Object: An entity used to describe an objective thing, consisting of a set of properties and methods.

Properties: The various characteristics that an object has. (member variable)

Method: The action performed by the object.

2. Class: A set of inductive types for an object with the same properties and methods. An object is a concrete representation of a class.

3. Object-oriented three major features: encapsulation, inheritance, polymorphism.

4. Step: Write a Class--create object--call a method of the class to complete a function.

Class Name Object name =new class name (); object. Property Object. Method

(actually a constructor)

5. Class: "Access control character" class name {}

Property: The Access control character data type variable name;

Method: "Access control" Void/return value type method name (parameter) {}

6. Constructor: public class name (parameter) {} is the same as the class name, no return value, initialization of the variable

7. Return value of the method: no return value: Void, return value returned, what type of return value to write, and write return.

8. Method Invocation: Call the method of this class, directly with the method name ();

Call the method of his class, class name Object name =new class name ();

Object. Method name ();

9. Encapsulation of classes: The data is combined with the behavior in a package, and the object's consumer hides the data (private) implementation, through the get and set methods to access the data. The data in the object is called the instance domain, and manipulating the data is called a method.

Boxing: The process of converting a basic data type (example: int) into its wrapper class (example: Integer).

Unpacking: Contrary to the boxing process.

10. The method of modifying the instance domain is called the Change Method (set), and the method that accesses only the instance domain without modification is called accessor method (get). Shortcut keys bring up get and set:alt+shift+s

11.this Keyword: represents the current object.

12. A method can access private data for all objects of the owning class.

13.final instance fields: objects are not modified after they are built, that is, there is no set method, usually the final is placed behind private.

14. Inheritance of classes: If component A inherits component B, then component A has all the members (properties and methods) of component B. Where component B is called a parent class or a superclass, component A is a subclass. Improve the reusability and extensibility of your code. Multilayer inheritance is allowed in Java (subclasses can be the parent of other classes), but multiple inheritance is not allowed (subclasses can only be subclasses of a class and cannot be subclasses of multiple classes). When you reference certain properties and methods of a parent class in a subclass, you can use super. Properties/Methods. When a constructor is used, a has a parent class B, the parent class constructor is called before the subclass constructor is called. If the parent class is not written, the parent class default constructor super () is called, and a super (argument list) is used if you want to invoke a constructor for the parent class. In an inheritance relationship, the subclass overrides the parent class's method, the name of the method, the parameter, and the return value to be the same as the parent class. Call a method, first in the subclass to find out if there is this method, if there is an overriding method, then he directly call the method of the subclass, if not, then from the parent class to find.

Local variables and global (member) variables: Member variables are properties of the object, and local variables are variables in the method. When two variables occur at the same time, local variables have high precedence. The local variable must be initialized, and the member variable can automatically assign the initial value: Null,0,false.

Java Object-Oriented foundation

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.