Classes and objects
Object: An object is an instance of a class (objects are not looking for a girlfriend), stateful and behavioral. For example, a dog is an object whose state is: color, name, variety, behavior: wagging the tail, barking, eating, etc.
Class: A class is a template that describes the behavior and state of a class of objects. Determines the set of attributes (attributes) and behaviors (methods) that an object will have to determine object information, a set of objects that have the same properties and methods
Software objects also have states and behaviors. The state of the software object is the attribute, and the behavior is manifested by the method.
Hash encoding : Each object has its own hash code, which, when called by the program, finds the object's location in memory by looking for the hash encoding of the object.
In software development, the internal state of the method operation object is changed, and the mutual invocation of the object is done by means of the method.
Properties: Characteristics of an object
Method: An action performed by an object
Defining classes
Class with the first letter capitalized to create the class
Defining objects
Class Name Object name = new class name ();
Using the properties of an object
Phone.screen
Ways to use objects
Phone.sendmessage ();
Construction method
Each class has a constructor method. If you do not explicitly define a construction method for a class, the Java compiler will provide a default constructor for the class.
public class Puppy{ public Puppy(){ } public Puppy(String name){ // 这个构造器仅有一个参数:name }}
Create a new object when you create an object, you execute a construction method.
Defines a method for initializing an object in a Java class
The constructor method has the same name as the class and no return value
The construction method can also assign a reasonable value to the object
Creating objects
Declaration: Declares an object, including the object name and object type.
Instantiation: Use the keyword new to create an object.
Initialize: When you create an object with new, the constructor method is called to initialize the object.
Puppy mypuppy = new Puppy ("Tommy");
Accessing instance variables and methods
Access member variables and member methods through the objects you have created, as follows:
```
/* Instantiate object /
Objectreference = new Constructor ();
/ access a variable in a class /
Objectreference.variablename;
/ access the methods in the class */
Objectreference.methodname ();
Java Basics-Classes and objects