classperson{String name; intAge ; String like; voidsetName (String name) { This. Name =name; } voidSetage (intAge ) { This. Age =Age ; } voidsetlike (String like) { This. like=Like ; } voidTalk () {System.out.println ("I am:" + name + ", this year:" + Age + "years," + "like:" +Like ); }} Public classclasswork{ Public Static voidMain (string[] args) {person P=NewPerson (); P.setname ("Xiao Ming"); P.setage (20); P.setlike (Music); P.talk (); }}
classBook {String title; DoublePrice ; Public voidPrintinfo ()//Book Information{System.out.println ("The name of the book:" + title + ", Price:" +Price ); }} Public classwork2{ Public Static voidMain (String args[]) {book Booka=NewBook (); Book BOOKB=NewBook (); Booka.title= "Program Design" ; Booka.price= 40.7 ; Bookb.title= "C Language" ; Bookb.price= 33.9 ; BOOKB=Booka; Booka.printinfo (); Bookb.printinfo (); }}
classBooks {PrivateString title; Private DoublePrice ; String Pub= "Every day Wonderful publishing house" ; PublicBooks (String title,DoublePrice ) { This. title =title; This. Price =Price ; } PublicString GetInfo () {return"Book Name:" + This. Title + ", Price:" + This. Price + "yuan, publishing house:" + This. pub; }} Public classwork3{ Public Static voidMain (String args[]) {Books B1=NewBooks ("Java Development Combat Classic", 59.8) ; Books B2=NewBooks ("Java Web Development Combat Classic (Basic)", 49.9) ; Books B3=NewBooks ("Android Development Combat classic", 68) ; System.out.println (B1.getinfo ()); System.out.println (B2.getinfo ()); System.out.println (B3.getinfo ()); System.out.println ("----------------------Publishing house renamed after-------------------------") ; B1.pub= "Wonderful Daily Press" ; B2.pub= "Wonderful Daily Press" ; B3.pub= "Wonderful Daily Press" ; System.out.println (B1.getinfo ()); System.out.println (B2.getinfo ()); System.out.println (B3.getinfo ()); }}
Properties in the "JAVA" call class