An in-depth study of object-oriented (formal parameters and return value issues in the first season of Java 3)

Source: Internet
Author: User

/*
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)

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.