Java basics and object 1, java Basic Object 1
It is estimated that it has been one year since I learned java. However, in this year, I had been playing fish for three days and setting up the Internet for five days. I feel like it is a waste of work if I don't change anything .. t-T. while reviewing java again, we also use blogs to record the learning process. okay, you don't need to talk about it anymore .. start text.
I will not talk about data types and operators, java history, tools, and other things. I am sending a blog for the first time. I think there is still a little excitement. \ (too many operators )/
Java is an object-oriented language, so we must understand the concept of objects.
An object is an abstract concept. There is a realm in java that is .. all objects .. that is to say, we can abstract everything in the world that can be described in words into objects. the following is an example.
Car is a very common thing. We try to abstract the car thing, but how can we abstract it?
In fact, it is very simple. It is OK to describe this object, as shown in figure
In this way, we will simply abstract this car. What I abstract is the attributes and methods of this car. Of course, this is not just a car, but the abstract process of all things is like this, it is OK to abstract its attributes and methods.
Attribute: As the name implies, it refers to the attributes of things, such as the height, weight, and age of a person. Method (behavior): it is worth doing: the same person can run, eat, sleeping, so running, eating, sleeping is a human way
Now that we abstract things, what should we do next? Are you finished? Of course not. We need to add these abstract attributes and methods into the class, for example
In this way, we have successfully packed (encapsulated) vehicles (things) into the class. (The class contains the abstract parts of the things, for example, all cars have colors, tires, and can run and play songs)
Now that we have successfully loaded the car into the class, we can use it now.
New Car () is the object for creating a new Car. Car = new Car () refers to the variable used for vehicles (the variables in java can be in Chinese) to indicate the object we created (new Car ());
Car. color = "red" is to initialize the color of the new car into a red car. The number of tires...
Car. Running () is the method to call the car.