4. Object-Oriented Fundamentals

Source: Internet
Author: User

Object Oriented first of all consider who to do? (Which object's method)
1. Methods for creating Classes
A class is abstract, a series of things with functional characteristics
Class Name {attribute; method;} Property: Member variable that describes the state (variable) method of a class: Member method that describes the behavior of the class (function) 2. Objects
2.1 Create object methods, objects are specific, something of a function. Class Name Object name =new class name () Note: Heap memory and Stack memory relationship: Heap memory is the Buddha, stack memory is a reference, equivalent to a name.
2.2 How objects are used all objects are in use by the Master: Object name. Method 2.3 Multi-object creation method heap memory and stack memory are separated, not affected.    2.4 Anonymous object creation and usage methods you can call this object directly by not defining the object's reference name. New Dog (). Jump () is usually a one-time, because there is no name, can not continue to use. 3. Functions3.1 function overloading two or more functions in the same class; The function name is the same; the parameter list is different; 3.2 Constructor class name Object name =new class name (), i.e.class name (), constructor and class name are the same. Use new to call the constructor. And the constructor does not have a definition of the return value. function: The constructor is automatically added to the class,the object that generated the class. Write your own constructor to assign a value to a member variable (the compiler does not automatically add an parameterless constructor after a person is added). New will execute the code of the program, no Java will be automatically added. A key feature of a constructor is that it executes before the object can be assigned to a reference. 4. Heap and StackHeap: Method calls and local variable stacks: All objects, also known as garbage-collected heaps, instance variables are declared inside a class rather than inside a method, and instance variables exist in the owning object. The top-of-stack method is executing.  There are three ways to dispose of object references: 1. Reference to permanently leave its range void Go () {Life z = new Life ();/z will disappear at the end of the method}2. References are assigned to other objects on life z = new Life ();   z = new Life ();//The first object will hang when Z is assigned to another 3. Set the reference directly to null life Z = new Life (); z = null; The first object is killed when Z is assigned a value of NULL.





From for notes (Wiz)

4. Object-Oriented Fundamentals

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.