Interface as a type in Java? -
From
From:
In Java, a class can inherit only one class but To apply more than one interface, therefore, objects can have several types : the type of their own class and the types of all the interfaces they execute mean that if any If the variable is declared as the type of interface, its value is referenced to any object Which can be instantly available from any class implementing the interface .
Someone could provide me a basic pseudo type for this, I did not understand the bold lines.
Let's declare two interfaces and one class that implements both:
I1 {} interface I2 {} class C I1, I2 {} objects can have many types
In the following code, it can be seen that with a
C in the example
C with
I1 and
I2 :
cc = new C (); Boolean isC = (c example c); // true boolean isI1 = (Example of I1); // true boolean isI2 = (c example i2); // true
We now declare a class
B which also implements
I1 :
Implementation of Class B I1 {}
If any difference is declared as an interface type, its value can be referenced to any object Which applies to any class that applies to that interface
If we declare a variable type of type , then for an example of it,
C You can set it, and then reassign it to
B :
I1 i1 = new C () for an example; I1 = new B ();
We can reassign this for an example of
D , where
D is expanded
C :
i1 = new D (); ... square dc {} extends
Comments
Post a Comment