Java public Class-01. Classes and Objects

Source: Internet
Author: User

Tag: equal to CTE another how to create a write code financial subclass reference type

First, the meaning of classes and objects

1. Class : A class is a collection of things that have the same attributes (static characteristics) and behaviors (functions).

Eg: The following two are not classes

1) Car √

2) The Red Cup on the chubby table X

2. Object : Be precisely limited to a special individual !

Eg: The following two are not objects

1) Auto X

2) The Red Cup on the chubby table √

3. Relationship of classes and objects:

A class is an abstraction of an object (template, skeleton, foundation)-----It is stored on the hard disk

An object is an instance of a class-------it is stored in memory

4. How do I refine my class? How many properties and methods do you want in a class?

Based on business requirements

5. How to have the above 4. Ability

1) First practise, practice makes perfect

2) Get out of the textbook and try More

3) MUI Wind Level: No computer can write code, even on the subway, bus, anywhere can be in the brain code

4) familiar with the business (if developing financial software, be familiar with financial knowledge)

Two, create a class yourself

eg

public class Book () {//Outer frame

Member properties

private int age;

Member Methods

public void Show (String bookname) {

System.out.println ("I Love You" +bookname);

}

}

1. Access Modifiers

    Public: can be anywhere

    private: in this class , (a decorated class cannot inherit, if the class is public, the subclass cannot access the properties and methods of the private adornment of the parent class)

    default , do not write the case, is the package level, can only be accessed in this package, it is protected

Three, create countless objects

1.eg:

public static void Main (String [] args) {

Book Book1=new book ();

Book1.show ("Java Programming idea");

Book Book2=new book ();

Book2.show ("algorithm");

}

2.New

1) New is to request memory from the JVM (Java Virtual machine) (JVM only 64MB)

2) The new object has its life cycle : When to return the occupied memory to the JVM?

Answer: When the object is unreachable, when the object does not have any pointers pointing to it

3) Because there is a JVM, so Java does not like the process-oriented and then the programmer manually the object is equal to null, eg:book1=null;

4)New has done three things: ①. Call construct ②. Creates an object ③. Open Space

5) Speaking of opening up space, reminds me of a picture I drew before, that is, the reference type on the stack to open up space and change the value of a process diagram, the object is a reference type, so I put a reference type example

eg

      

Four. Interaction between objects

1. In one class you can define another class as the data type of the member variable

It can access the properties and methods of the instance object of that class in this class

Java public Class-01. Classes and Objects

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.