Java Classes and objects

Source: Internet
Author: User

//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

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.