Java Practice---11

Source: Internet
Author: User

 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

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.