//class: A set of things that have the same properties and behaviors (methods). //object: Is a specific thing, is a characteristic of an individual. is a kind of real existence thing. //A class consists of properties and methods://Properties: Features//methods: Behavior, such as people talking, eating, singing, etc. /**How to define a class: class name {attribute name; Return value type method name () {}}//How do I create an object? class name [space] Object name =new class name ();//Access a Property object in a class.//The method in the calling class: Object. Method ()*/ Public classtest16{//properties of the class: intColor//1: White, 2: Black, 3: gray;String name; intAge ; //the behavior of the class: voidCat () {System.out.println ("I like to eat small fish ~"); }//void indicates a return value voidborn () {System.out.println ("I can be eaten."); } //Creating an object procedure Public Static voidMain (String args[]) {//Executive PortalTest16 d1=NewTest16 (); D1.color=1; D1.name= "Xiaodeng"; D1.age=28; D1.cat (); D1.born (); }}
Java Classes and objects