Java_se Foundation--45. Polymorphism under the interface relation

Source: Internet
Author: User

The polymorphism under the interface relationship is almost the same as that in the inheritance relationship, it should be simpler ~


Polymorphic: The reference-type variable of the parent class refers to the object of the subclass, or the reference-type variable of the interface type that points to the object of the interface implementation class.



To implement polymorphism under a relationship:

Interface variable = new interface implements the object of the class.




The package day09;interface dao{  //interface methods are all non-static methods. public void Add ();p ublic void Delete ();} Interface implementation Class class Userdao implements Dao{public void Add () {System.out.println ("Add Employee success!! ");} public void Delete () {System.out.println ("Delete employee success!! ");}} Class Demo12 {public static void main (string[] args) {///implementation-related polymorphic DAO d = new Userdao ();//The reference-type variable of the interface points to the object of the interface implementation class. D.add ();}}
Operation Result:




The polymorphism under the relationship of the relationship between the polymorphism and the interface is not very much the same, can fully grasp the inheritance relationship, it will be able to master the multi-state after the implementation of the relationship.


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java_se Foundation--45. Polymorphism under the interface relation

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.