<> object

. Three characteristics of object-oriented : Encapsulation , Inheritance and polymorphism , There is no inheritance and polymorphism in process oriented , And process oriented encapsulation is just encapsulation function , Object oriented can encapsulate data and functions . So the object-oriented advantage is more obvious .

<> Summary of object oriented and process oriented

1, It's all a problem-solving way of thinking , It's all code organization .

2, Process oriented can be used to solve simple problems

3, Solving complex problems : Macro use of object-oriented grasp , Micro processing is still process oriented .

<> What is an object

1. Object is also a data structure ( Management mode of data ), Put data and data behavior together .

2. In memory , Object is a block of memory , Relevant data set stored

3. The essence of an object is a way of organizing data

<> Classes and objects

1. Objects are concrete things ; A class is an abstraction of an object ;

2. Class can be regarded as a template for a class of objects , Object can be regarded as a concrete instance of this class .

3. Class is an abstract concept used to describe objects of the same type , Class defines the common properties that this class of objects should have , method .

Let's define a student class SxtStu:
public class SxtStu { // attribute ( Member variable ) int id; String sname; int age; // method void study
(){ System.out.println(" I am learning !"); } // Construction method SxtStu(){ } }
<> attribute

Property is used to define the data or static characteristics contained in this class or its objects . Property scope is the whole class , Member variables can be initialized when they are defined , If it is not initialized ,Java Initialize it with the default value .

<> method

Method is used to define the behavior characteristics and function implementation of this class or its instance . Methods are abstractions of behavior characteristics of classes and objects . Methods are very similar to functions in process oriented . Process oriented , Function is the most basic unit , The whole program consists of function calls . Object oriented , The basic unit of the whole program is the class , Methods are subordinate to classes and objects .

practice :
class Computer{ String brand;// brand } public class est { int id; String name; int
age; Computer comp; void study() { System.out.println(" I am learning ! Computers used ," + comp.
brand); } est() { } public static void main(String[] args) { est stu1 = new est(
); stu1.name = " Woods "; Computer comp1 = new Computer(); comp1.brand = "lenovo";
stu1.comp = comp1; stu1.study(); } }
Running screenshot :

©2019-2020 Toolsou All rights reserved,
It's unexpected Python Cherry tree (turtle The gorgeous style of Library )Unity3D of UGUI Basics -- Three modes of canvas os Simple use of module computer network --- Basic concepts of computer network ( agreement , system )html Writing about cherry trees , Writing about cherry trees Some East 14 Pay change 16 salary , Sincerity or routine ?Unity-Demo Examples ✨ realization UI- Backpack equipment drag function 06【 Interpretation according to the frame 】 Data range filtering -- awesome java Four functional interfaces ( a key , simple )