Java Simple class

Source: Internet
Author: User

1  PackageObject-Oriented Programming _ encapsulation;2 //1. The class name must be meaningful, such as book, Emp3 //2. All attributes within a class must be encapsulated in private, and the encapsulated property must provide a setter and getter method4 //3. Multiple construction methods can be provided in a class, but there must be a non-parametric construction method reserved5 //4. No output statements are allowed in the class, and all information output must be given to the output to be tuned6 //5. There is a need to provide a method for obtaining complete information about the object, tentatively: GetInfo; returns string Data7 8 /**9 * Created by Administrator on 2017/6/26.Ten  */ One  A classbook_demo{ -     PrivateString title; -     Private DoubleMoney ; the  -      PublicBook_demo () {} -      PublicBook_demo (String T,Doublem) { -title =T; +Money =m; -     } +  A      Public voidSettitle (String t) { attitle =T; -     } -      Public voidSetmoney (Doublem) { -Money =m; -     } -  in      Public DoubleGetmoney () { -         returnMoney ; to     } +  -      PublicString GetTitle () { the         returntitle; *     } $      PublicString GetInfo () {Panax Notoginseng         return"Name:" + title + "\ T" + -"Price:" + Money + "\ n"; the     } + } A  the  Public classsimple Java class { +      Public Static voidMain (string[] args) { -Book_demo book =NewBook_demo ("Java development", 66.6); $Book.settitle ("Python development");//with modifications $ System.out.println (Book.getinfo ()); - System.out.println (Book.gettitle ()); -  the     } -}

Java Simple class

Related Article

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.