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