Packagecn.lyhh;classperson{PrivateString name; Private intAge ; StaticString city = "a castle"; PublicPerson (String name,intAge ) { This. Name =name; This. Age =Age ; } PublicString GetInfo () {return"Name:" + This. Name + ", Age:" + This. Age + ", City:" +City ; }} Public classL { Public Static voidMain (string[] args) {person Per1=NewPerson ("Zhang San", 30); Person Per2=NewPerson ("John Doe", 31); Person Per3=NewPerson ("Harry", 30); System.out.println ("====== ====== before modifying information"); System.out.println (Per1.getinfo ()); System.out.println (Per2.getinfo ()); System.out.println (Per3.getinfo ()); System.out.println ("====== ====== after modifying information"); Person.city= "City B"; System.out.println (Per1.getinfo ()); System.out.println (Per2.getinfo ()); System.out.println (Per3.getinfo ()); }}
PackageCn.lyh;classl{Private StaticSingle Instance =NewSingle (); PrivateSingle () {} Public StaticSingle getinstance () {returninstance; } Public voidprint () {System.out.println ("Hello World!!!"); }} Public classLL { Public Static voidMain (string[] args) {single S=NULL; S=single.getinstance (); S.print (); }}
Package Cn.lyh;classperson{PrivateString name; Private Static intcount; PublicPerson () {count++; This. Name = "NONAME-" +count; } PublicPerson (String name) { This. Name =name; } PublicString GetInfo () {return"Name:" + This. Name; }} Public classly{ Public Static voidMain (string[] args) {System.out.println (NewPerson (). GetInfo ()); System.out.println (NewPerson ("A"). GetInfo ()); System.out.println (NewPerson ("B"). GetInfo ()); System.out.println (NewPerson (). GetInfo ()); }}
PackageCn.lyh;classperson{PrivateString name; Private Static intcount; PublicPerson () {count++; System.out.println ("Generated" + Count + "instantiation"); } PublicString GetInfo () {return"Name:" + This. Name; }} Public classY { Public Static voidMain (string[] args) {NewPerson (); NewPerson (); NewPerson (); NewPerson (); NewPerson (); }}
Package Cn.lyh; Public class LYH { publicstaticvoid main (string[] args) { for ( int x=0;x<args.length;x++) { + ","); }}}
Java Practice---11