Java Chapter Tenth

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.