On transition objects and interface callbacks

Source: Internet
Author: User
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!

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.