Understanding of classes and objects

@About class and object knowledge

Classes and objects

These days I learned classes and objects at Lan Jie

When I was learning C ++ in my sophomore year, I first came across the concept of classes and objects. At that time, I remembered my understanding that because I was learning object-oriented programming, classes and objects should be related to that.
Later, with the deepening of the course, my understanding of it has changed again. I know I want to define a class, and then write out the header file .h, and then variables and methods can be defined in the class. These variables and methods can be set to public, protected, and private. These three are for better confidentiality and encapsulation.
After learning the inheritance of classes superficially, I ended the study of C ++.
After coming to Lanjie these days, I came into contact with classes and objects from the Java level again.
First look at its definition.
Class and object (class) are the collective names of two computer languages ​​that use computers as carriers. Objects are abstractions of objective things, and classes are abstractions of objects. Class is an abstract data type.
Their relationship is that objects are instances of classes, and classes are templates for objects. The object is generated by new className, used to call the method of the class; the constructor of the class.
Insert picture description here
Then these days I wrote these classes, which are basically listener classes.
The first time I wrote a class and called it in the public static void main (String [] args) {} function, there was such a problem.
Insert picture description here
It reported an error, and then I checked the error and added such a sentence
Insert picture description here
to solve it. Now, DrawUI is the class I defined, and DrawUI ui = new DrawUI (); is to create a DrawUI object. With it, I can call the content in the class! Only then did I understand the meaning of classes and objects for the first time.
same

Insert picture description here
Insert picture description here
Insert picture description here
These are also applications of classes and objects, but the difference is that these are classes already written in Java. We only need to create a corresponding object to use, and these classes can be viewed in the API documentation.
In other words, in my opinion, first of all, the program is equal to the algorithm plus the data structure. And we must have our own purpose in programming, which is the goal we want to achieve, and in order to achieve this purpose, we have defined one class after another, which is equivalent to one tool after another. This tool has various attributes, and then When we want to use it, we can define an object. This object has all the attributes of that class, which is equivalent to all the capabilities of that tool. (Probably the meaning of the mold and model) Finally, the problem-solving effect is achieved.

Published 13 original articles · Like1 · Visits 307

Guess you like

Origin blog.csdn.net/Alagagaga/article/details/102843470