PackageCom.swift;//automatic generation of objects using the parameterless construction method, the serial number is continuously self-increasing Public classPerson {Private Static intCount//If you are using static properties when defining a class, you will get a different result. Count life cycle long, same as class Public intID; PublicString name; Public intAge ; PublicString City; PublicPerson () {Super(); Count++; This. id=count; This. Name= "NoName" +count; This. age=20; This. city= "Shu"; System.out.println ("produced" +count+ "instantiated objects");//output} When calling Null parameter construction method PublicPerson (intID, String name,intage,string City) { This. id=ID; This. name=name; This. age=Age ; This. city=City ; } Public intgetId () {returnID; } Public voidSetId (intID) { This. ID =ID; } PublicString GetName () {returnname; } Public voidsetName (String name) { This. Name =name; } Public intGetage () {returnAge ; } Public voidSetage (intAge ) { This. Age =Age ; } PublicString getcity () {returnCity ; } Public voidsetcity (String city) { This. City =City ; } PublicString GetInfo () {return"The person was id=" + ID + ", name=" + name + ", age=" + Age + ", city=" +City ; } }
What is an anonymous object in Java, the null parameter constructor method output creates several anonymous objects, and the properties are declared as static