1 Packagetest;2 3 classA4 {5 Private Static intI//Static, Private Attribute6 Private Static intJ//Static, Private Attribute7 Private Static intCNT = 0;//statistic The number of the object8 voidSetintAintb//Set The value by the function in class9{//The security can be guaranteedTeni =A; Onej =b; A } - - PublicAintAintb//Construction Method the { -System.out.printf ("The function has been called!\n"); -i =A; -j =b; +cnt++; - } + A Public Static intCnt ()//Get The number of the object in this class at{//It should can be static because we can - returnCnt//a.cnt - } - - Public voidShow ()//A Show Method in the class - { inSystem.out.printf ("The value in this object:i=%d,j=%d\n", i,j); - } to + - } the * $ ///////////extends/////////////////////Panax Notoginseng classHuman - { the PublicString name = "Mike"; + Public intAge = 22; A } the + classStudentextendsHuman - { $ Public DoubleScore = 90; $ } - - classGraduateextendsStudent the { - PublicString tutor = "Jay";Wuyi } the /*************extends**********************/ - Wu - Public classTestmemo { About $ Static intAddintAintb//The reentry of a function - { - return(A +b); - } A + Static intAddintAintBintC//The reentry of a function the { - return(a+b+c); $ } the the Static DoubleAddDoubleADoubleb//The reentry of a function the { the returnA +b; - } in Public Static voidMain (string[] args)//The reentry of a function the { theA AA =NewA (66,88); About //aa.i = +; the //AA.J =; the //Aa.set (in); the aa.show (); +SYSTEM.OUT.PRINTF ("Both int value be plused:%d\n", add (2,8)); -SYSTEM.OUT.PRINTF ("Three int value be plused:%d\n", add ()); theSystem.out.printf ("Both float value be plused:%f\n", add (1.9,2.0));BayiA BB =NewA (12,10);//Change the value in the class by another object theAa.show ();//because of the static attribute theSystem.out.printf ("The Vaule count in A class:%d\n", a.cnt ()); -Graduate Stu =Newgraduate (); -System.out.printf ("Test of EXTENDS:%s ' s tutor is%s\n", stu.name,stu.tutor); theSystem.out.printf ("Test of EXTENDS:%s ' s is%d\n", stu.name,stu.age); the } the}
Java Programming test (1)