What are the relationships between classes and object classes and objects? A: A class is a collection of a set of objects that have the same properties and methods. The class is abstract, the object is concrete, the class is the template of the object, and the object is an instance of the class. What is the syntax for defining a class? public class class Name {//Define Attribute section property 1 for Type attribute 1, property 2 for Type attribute 2;//can have multiple properties. As long as required properties;//define method part Method 1; Method 2;//can have multiple methods. Take only the methods that are used. How do I create an object of a class? Class Name Object name =new class name (); School Center = new School (); Note://First initial letter must be capitalized basic data type four eight kinds://1. integer int age=21; long age2=21; byte age3=21, or ' A '; short age4=21; 2, float type float score1 =21.2f; Single-precision floating-point double score2 = 32.2//double-precision float//3, character char s = ' A '; 4. Boolean Boolean flag =true;//true/false//reference data type String str =new string ("AA"); Int[] Ages =new int [5]; Custom type classes (Class) Student Stu =new Student (); Interface//string Buffer//enum enum//wrapper type--boxing (integer) also belongs to int type integer age 6=32;
Summary:
Real-world objects are composed of properties and methods,
Can be seen, tangible entities we can call the object.
(Objects of all things)
Steps to define a class
1. Defining the class name
2. Writing the properties of a class
3. Methods for writing classes
~ In accordance with the habits of the human mind
-Turning the human problem-solving process into a process that can be understood by the program
~ Information hiding, which improves the maintainability and security of the program
-Encapsulation enables modularity and information hiding
-Encapsulation makes it impossible to access objects ' properties and methods outside the object
~ Improved reusability of programs
-A class can create multiple object instances, adding reusability
Summarize:
An object is an entity used to describe an objective thing.
class defines the characteristics (attributes) and behaviors (methods) that an object will have
Class is the type of the object, and the object is an instance of the class
Java Chapter Tenth