1 PackageCom.mon11.day2;2 /** 3 * Class Description: Construction method, variable parameter list4 * @authorAuthor: Chenyanlong5 * @versionCreation Date: November 2, 20176 */7 classemployee{8 Private Doublesalary=1800;9 Ten //Construction Method One PublicEmployee () { ASystem.out.println ("Construction method called"); - } - the //Redefining Methods - Public voidgetsalary () { -System.out.println ("Basic salary of staff" +salary); - } + - //variable parameter list + Public DoubleAddint.. is) { A DoubleResult=0; at for(inti=0;i<is.length;i++){ -Result + =Is[i]; - } - returnresult; - - } in - } to + - Public classTestemployee { the * Public Static voidMain (string[] args) { $Employee a=NewEmployee ();Panax Notoginseng a.getsalary (); - theSystem.out.println ("Output:" +a.add (12)); +System.out.println ("12, 13 and output:" +a.add (12,13)); ASystem.out.println ("12,13,14 Output:" +a.add (12,13,14)); theSystem.out.println ("12,13,14,15 Output:" +a.add (12,13,14,15)); + } -}
View Code
Operating effect:
Java Foundation Summary-----Construction method, variable parameter list