A detailed description of the formal parameters in Java

Source: Internet
Author: User

In Java, formal parameters mainly have basic types, class names, abstract class names, interface names. Let's tell each of them.

1. Basic type This is too simple to be brief.

2. Class name

Class Name: An object that requires this class

1 classStudent {2      Public voidStudy () {3System.out.println ("Good good study,day day up");4     }5 }6 7 classStudentdemo {8      Public voidMethod (Student s) {//SS; ss = new Student (); Student s = new Student ();9 s.study ();Ten     } One } A  - classStudenttest { -      Public Static voidMain (string[] args) { the         //requirements: I want to test the study () method of the student class -Student s =NewStudent (); - s.study (); -System.out.println ("----------------"); +          -         //Requirement 2: I want to test method () methods in the Studentdemo class +Studentdemo SD =NewStudentdemo (); AStudent SS =NewStudent (); at Sd.method (ss); -System.out.println ("----------------"); -          -         //Anonymous Object Usage -         NewStudentdemo (). Method (NewStudent ()); -     } in}

  3. Abstract class Name: A subclass object that requires this class

Abstract classPerson { Public Abstract voidstudy ();}classPersondemo { Public voidMethod (person p) {//p = new Student (); Person p = new Student (); // polymorphicP.study (); }}//define a specific class of studentsclassStudentextendsPerson { Public voidStudy () {SYSTEM.OUT.PRINTLN ("Good good study,day day up"); }}classPersontest { Public Static voidMain (string[] args) {//There's no way to use it at the moment .//because the abstract class has no corresponding concrete class//So, we should first define a specific class//requirement: I want to use method () in the Persondemo classPersondemo PD =NewPersondemo (); Person P=NewStudent ();    Pd.method (P); }}

4. Interface Name: An implementation class object that requires this interface

is similar to the abstract class name

1 //define a hobby's interface2 InterfaceLove {3      Public Abstract voidLove ();4 }5 6 classLovedemo {7      Public voidMethod (Love L) {//l; l = new Teacher (); Love L = new Teacher (); polymorphic8 L.love ();9     }Ten } One  A //defining a concrete class implementation interface - classTeacherImplementsLove { -      Public voidLove () { theSYSTEM.OUT.PRINTLN ("Teachers love students, Love Java, love Brigitte")); -     } - } -  + classTeachertest { -      Public Static voidMain (string[] args) { +         //requirement: I want to test the Love () method in the Lovedemo class ALovedemo ld =NewLovedemo (); atLove L =NewTeacher (); - Ld.method (l); -     } -}

A detailed description of the formal parameters in Java

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.