/*
Formal parameters:
Reference type
Interface: The implementation class object for the interface is required
This time is nothing, and the interpretation of the abstract class is similar.
*/
Interface Love {public abstract void Love ();} Class Lovedemo {public void method (Love L) {l.love ();//If you see that the reference type within a method is an interface type, the implementation class object of the interface should be passed here. }}//defines a concrete class implementation interface, the implementation class class Teacher implements Love {public void Love () {System.out.println ("formal parameter is the interface type");}} Class Teachertest {public static void main (string[] args) {//requirement: Test the Love () method in the Lovedemo class Lovedemo ld = new Lovedemo (); Love L = new Teacher ();//Belongs to polymorphic Ld.method (l); Teacher t = new Teacher (); Ld.method (t);}}
/* Return value type reference type: Interface: Object that returns the implementation class of the interface *///defines a hobby interface interface Love {public abstract void Love ();} Class Lovedemo {public Love Getlove () {return new Teacher ();//Anonymous object}}//definition concrete class implementation interface class Teacher implements love {public void Love () {System.out.println ("Return value type is interface type");}} Class TeacherTest2 {public static void main (string[] args) {Lovedemo ld = new Lovedemo (); Love L = Ld.getlove (); belongs to polymorphic mode L.love ();//Callable}}
An in-depth study of object-oriented (formal parameters and return value issues in the first season of Java 3)