Jen Baby Java basic notes and objects

Source: Internet
Author: User

One, the object
Object: An objective thing is an object.
Object contains: attributes (Features) and methods (actions)
Two, class
Class: A collection of groups of objects that have the same properties and methods.
The relationship between classes and objects is abstract and concrete. A class is a collection of objects that are instances of a class.

Steps to define a class
1. Define Class name

2. Write the properties of the class
3, the method of writing classes
public class < class name >{
Defining Attributes Section
Define variables to describe the properties that the class has, which are called member variables of the class.
Define Method Section
Access modifier return value type method name () {
Method body
}
}
Creating and Using objects
Class Name Object name =new class name ();
Strudent Stu =new Student ();
The object name. Properties
Stu.name= "Zhang San"; Arr.length
Object name. Method Name
Stu.learn (); Input.next ();
Attention:
1. Class properties and methods name the same variable
2. When a class is defined, the member variable can be assigned or not, and when not, the system automatically assigns a default value.
A variable within a method must have an initial value assigned to it.
3. When a class is defined, the nearest value principle is when the variable defined in the method has the same name as the global variable.


Jen Baby Java basic notes 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.