Java learning notes-6. Object-Oriented Programming 01-Class Object Construction and Object Reference Transfer

Source: Internet
Author: User

Different from C ++, Java is a pure object-oriented language. Object-oriented has three main features: inheritance, encapsulation, and polymorpism ).

 

This part contains a lot of content. 01 I will take an example to familiarize myself with the Java Class Object Construction Process. Here I need to remember one thing: In Java, the transfer of class objects is reference transfer.

Example:

Class person {// defines the property string name; int age of the class "person"; // defines the method void say () {system. out. println ("My name is:" + name + ", my age is:" + age) ;}} public class oodemo01 {public static void main (string ARGs []) {// declared object: declared in stack memory; Class Name object name = NULL; // instantiated object: Use new to open up space in heap memory and save object attributes; object Name = New Class Name (); person P = new person (); // pass through the object. attribute to set the property P. name = "James"; p. age = 23; // pass object. method: Call the Method P of the object. say ();}}

In this example, a person class is defined. To use a person class object in the main method, a person object must be declared and instantiated. The declared object is allocated in the stack memory. The instantiated object adopts the new class name () syntax to open up space in the heap memory. The objects allocated in the stack memory are referenced to operate the heap memory data.. This is very important and requires thorough understanding.

The above object construction process can be used to express the object reference transfer.

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.