Day seventh (object-oriented)

Source: Internet
Author: User

(1) This: is the corresponding reference of the current class. In simple terms, it represents an object of the current class.

This scenario: Resolves a local variable hidden member variable.

(2) Construction method:

Function: Initializes the data for the object.

Format: 1. The method name is the same as the class name; 2. No return value type, not even void; 3. No specific return value.

Class Student () {

      Public Student () {

System.out.println ("This is the construction method");

}

Note: If we do not give a construction method, the system will automatically provide a non-parametric construction method.

Student s = new Student (); What does it do in memory:

A: Load the Student.class file into memory;

B: In the stack memory to the s variable to open up a space;

C: In the memory for the student object to apply for a space;

D: Default initialization of member variables;

E: Display initialization of the member variables;

F: Initialize the member variables by constructing the method;

G: Data initialization is complete, then the address value of the heap memory is assigned to the stack memory s variable.

(3) Static: static.

Features: (It can modify member variables and can also modify member methods)

A: Loads as the class loads.

B: Precedence over object existence.

C: Shared by class on all objects.

D: Can be called by object name, or by class name.

(4) Private:

A: Private meaning, can modify member variable and member method
B: Features: Members who have been modified by private can only be accessed in this class
Application of C:private:
To write a class later:
Give all the member variables to private.
provides the corresponding getxxx ()/setxxx () method

(5) The Main method is static:
Public: Maximum Permissions
Static: Do not create object calls
void: Return value does not make sense to the JVM
Main: is a common name.
String[] args: Can receive data, flexibility of the provider
Format: Java maindemo Hello World Java
Java Maindemo 10 20 30

  

Day seventh (object-oriented)

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.