My question: public class myimplclass ustements myinterface {} in another file: Myinterface myobj = new myImplclass ();
1 myobj pointing to the object created by MyImplclass, what is going on? Myob is an instance of the interface? 2 Why don't you build a reference to its own created object? --MYIMPLCLASS (); Answer: chDW (米) Myobj is a MyImplclass instance, of course, a MyInterface instance MyImplclass myobj = new myimplclass (); this is of course also correct, there is no nature of nature Kaymo ( Hair is familiar) Myobj points to the object created by class MyImplclass, but only the method in the interface is limited to JFRESH_MAN () 1. It is a polymorphic manifestation of Java, such a definition method is a "IS-A" mode Myobj is an instance of the interface but reference is a class object 2. Polymorphism! This creation of objects can be used to use this type of method, or the function of the interface can create an instance object of MyImplClass, which gives this object to a reference to MyInterface, which is legal. Nothing why, this is to tell you that this usage is naturally useful in some cases. J2NIX (Love Life Love Star Hui) 1 This interface cannot be instantiated, but for this polymorphism, the interface is to be understood as an abstraction class. 2 This is, it's right. However, it is not very flexible in use. Fog628 myinterface myobj = new myImplclass (); Java is a natural dynamic state, so doing this can determine which type of aspect will be called at runtime, one sentence, or polymorphism. NWPULIPENG (★ ★ Java programmer ★★) is the same as the object of the base class with the base class. Summary: 1 The number of methods defined in MyImplclass is the same as the MyInterFace definition, that is, the two formats. 2 The method defined in the interface will have several classes that implement it. However, the implementation of this method in different implementations is different, which is the polymorphism. Myinterface myobj = new myImplclass (); what to do is to make this method more flexible.