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