The understanding of the Transition object
Class AA
{
void func ()
{
System.out.println ("Class AA");
}
Class BB extends AA
{
void func ()/rewrite method
{
System.out.println ("Class BB");
}
Class CC extends AA
{
void func ()/rewrite method
{
System.out.println ("Class CC");
}
public class Test7
{public
static void Main (String args[])
{
AA A;
A = new AA ();
A.func ();
A = new BB ();//a is the upper transition object of BB object
A.func ();
A = new CC ();//a is a transition object on the CC object
a.func ();
}
Output:
Class AA
Class BB
Class CC
PS: The transition objects are generally used when the abstract class
############################################################################################################### #####################
Interface callback:
Assigns a reference to an object created by a class that uses an interface to the interface variable declared by the interface. Then the interface variable can call the method in the interface implemented by the class, when the interface variable calls the method in the interface implemented by the class, it is the method that notifies the corresponding object to call the interface, and this process is called the callback of the interface.
Understanding of Interface Callbacks
interface I
{
hello ();//interface when declaring a method, you can omit the public and abstract
} class AB in front of the method
implements I
{public
void Hello ()//But when implementing an interface in a class, be sure to have public to modify
{
System.out.println ("Hell world!");
}
class CD implements I
{public
void Hello ()//But when implementing an interface in a class, be sure to have public to modify
{
System.out.println ("Hello Java!");
}
Public
class Test8
{public
static void Main (String args[])
{
I i;//interface variable I holds the reference to the object
i = new AB ();
I.hello ();//Interface callback
i = new CD ();
I.hello ();//Interface Callback
}
}
Output:
Hell World!
Hello Java!