Java first day classes and objects

Source: Internet
Author: User

What is a class?

A class is a collection of objects with the same properties and methods, and is an abstract concept

What is an object?

All objective things can be called objects, which are objective

Properties : Characteristics of an object

method : Function of object, operation

Name of the class name method: The first letter all need capital, pay attention to the code specification!!

The class file is in *. The Java method is named

After the class is instantiated, its properties and methods are loaded into memory

The float variable must be assigned a value of f, otherwise it is a double type

Two: member variables and local variables

Member variables are defined in the class and can be accessed by the class, scoped to the current entire class

A local variable is defined in a class method and can only be accessed in a method, scoped only to that class of methods

The member variable is given an initial value, and the local variable is not assigned the initial value

when two types of variables have the same name, local variables have higher precedence (the nearest principle )

Three: Construction method

new+ construct method can create a new object

The constructor method has the same name as the class, and the tangent has no return value

In a package is not allowed to have the name of the class, different packages can have the same name of the class, according to the package name + class names to distinguish

The package is named in all lowercase letters, COM. Company Name ...

The main functions of the inner class are as follows:

1. The inner class provides a better encapsulation that hides the inner class within the outer class and does not allow other classes in the same package to access the class

2. The method of the inner class can access all the data of the external class directly, including the private data

3. Functions implemented by internal classes can also be implemented using external classes, but sometimes it is easier to use internal classes

Java first day classes and objects

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.