Java Programming test (1)

Source: Internet
Author: User

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)

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.