Behavior of the object

Source: Internet
Author: User

The behavior of the object:

1, master the Declaration and invocation of the class method;

2, understand the method call stack;

1), the invocation of the method;

2), select the statement;

3), cyclic statements;

3, understand the method of overloading;

4, the understanding of the construction device;

☆ Object-oriented First principle: Single duty (one way to do a thing)

Code Analysis:

(a):

public class date{

Public Int. Day, month, Ysar;

public int GetDay () {

Systen.out.println ("Within the Getday method");

Return day;

}

Publiv void PrintDate () {

System.out.println ("Within the PrintDate method");

SYSTEM.OUT.PRINTLN (month + "/" + Day + "/" + year);

}

}

Two

public class dateprogram{

public static void Main (String [] args) {//1, enter main run

System.out.printlin ("Inside the Main method ..."); 2. Print in console: Inside the Main method ...

Date today = new Date;

Today.day = 2; Set Month: 2

Today.month = 14; Set Date: 14

Today.year = 2009; Set Year: 2009

System.out.println ("Days are:" + today.getday ()); 3, 1): Call "Today.getday" into (a):p ublic int GetDay () {

Printing in console: Inside the Getday method

2): Print in console: Number of days: 2

System.out.println ("Print date ..."); 4. Print in console: print date ....

Today.printdate (); 5, 1): Call "Today.printdate" into (a): Publiv void PrintDate () {

Printing in console: Inside the PrintDate method

Print in console: 14/2/2009 (based on print arrangement: Month + "/" + Day + "/" + year)

System.out.println ("What is the next display?")         "); 6, in the console printing: What is the next display content?

Today.getday (); 7. Call "Today.getday" to enter (a):p ublic int GetDay () {

Printing in console: Inside the Getday method

}

}

Method Signature:

The signature of a method includes information such as the method name, the parameter list, the data type of the return value, and so on.

Method overloads:

A class has two different methods to multiple names but different parameter lists.

Type, number

First, there are no arguments:

"Non-parametric construction"

Public Preson () {

    

}

"With a reference to the structure"

Public person (String [] args) {

Example this.name= name;

Example this.age = 18;

Example This.gender =true;

}

☆ Boolean : Boolean in Get/set method  ;

The automatically generated get method generates data as:"is." Gender " not applicable with existing methods need to be changed manually

Manual change: Change data to: "Get." Gender "

Constructor:

Role: Generating objects

Memory Area Division: 4 Zones

Heap area: New data: Basic data

Stack area: Local variables

Data segments: reference types, String constants

Code snippet:

This

This:1): Property, 2) method This refers to the current object.

This (): a constructor method calls the other construction method of this class, so as to achieve the construction method code reuse;

Can only be written in the first sentence of the construction method

Behavior of the object

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.