Object-oriented Java

Source: Internet
Author: User

In the early stages of programming, programmers write programs based on the process of the program, which is called structured programming. Now also a lot of structured programming language is widely used, the most prominent is the C language.

Slowly people find that there are some common attributes and behaviors in these programs, and then extract the concepts of these objects with the same properties and behaviors out of class, by designing objects around the problem to be solved, and writing a class for each object that describes the behavior and properties of the object. Such programming is called object-oriented programming. A class is a description of an object, and similarly an object is an instance of a class. So what kind of a class is it?

 Public classHuman {//Properties://properties are defined in the same way as variablesString name;//nameString gender;//Sex    intAge//Age//Behavior://and behavior is the action that the object in the class has--Methods//Example: Running behavior     Public voidrun () {System.out.println (Running); }}

A class created by a human template. It has properties that are also known as member variables, and it behaves as a method. Then the class has to instantiate the object through the constructor (a special method of constructing the class, each class having at least one constructor).

New Human ();

Procedure for creating an object: 1. Partition the memory space of an object in the heap 2. Allocate memory space to properties and methods such as 3. Assigns the initial value 4. Executes the statement in the constructor (this is the default constructor so it is not executed) the properties of the created object are the initial values. So what if we want the object to be assigned the value we want in the process of creating the object? Then we need to use a parametric constructor.

 Public int Age ) {     this. Name = name;       this. gender = gender;      this. Age = Age ;}                                            

Objects with different initialization values are created from different constructors.

Object-oriented Java

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.