Java Fundamentals 1

Source: Internet
Author: User

I. Classes and objects

1. Encapsulation class

public class class Name {

Defining properties

Private data type variable name

Defining methods

Public return value type method name (parameter name) {

Concrete implementation of the method}

}

2. Create object: Call the constructor with the new keyword to create an object

Construction method: is a very special method, the method name and the class name are the same, and there is no return value and does not require the void keyword.

Call construction Method: Data type variable name = new construction Method (parameter value);

Call the Normal method: Object variable name. Method name (parameter value);

Second: Variable explanation

1. member variables (attributes) and scope

A member variable is a variable, also called an attribute, that is defined in a class body, outside of a method. The scope of a member variable is the entire class body.

2. Local variables and scopes

A local variable is a variable defined within a method body. The scope of a local variable is in the current method body.

Three: Method overloading

Overloaded (overload): In a class, there are two methods whose names are the same, but the parameter list is different. [Overloaded with constructor method]

Four: this keyword

Each non-static method of each class (not statically decorated) contains a This reference name, which points to the object that called the method.

1. Show the call member variable [method parameter name and member variable name simultaneously]

public class thistest{int x;int y; public void init (x, y) {this.x=x;this.y=y;}

public static void Main (String args[]) {thistest p = new Thistest (); P.init (4,3);}}

2. Show other constructor methods that call this class [used in the first row of the constructor method, you can display other constructor methods that call this class]

Java Fundamentals 1

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.