java interface

Interface (English: Interface), in the JAVA programming language, is an abstract type and a collection of abstract methods. Interfaces are usually declared as interfaces. A class inherits the abstract methods of the interface by inheriting the interface.

An interface is not a class, the way of writing an interface is very similar to a class, but they belong to a different concept. A class describes the properties and methods of an object. An interface contains the methods to be implemented by the class.

Unless the class implementing the interface is an abstract class, the class defines all the methods in the interface.

An interface cannot be instantiated, but it can be implemented. A class that implements an interface must implement all the methods described in the interface, otherwise it must be declared as an abstract class. In addition, in Java, interface types can be used to declare a variable, they can be a null pointer, or be bound to an object implemented by this interface.

An interface case that realizes the performance of different mobile phones! ! ! ! !

package phone;
/**
 *
 * Inherit the Network and playwi ring interfaces while inheriting the Handset class
 * @author langlang
 *
 */
public class AptiudeHandset extends Handest implements Network,PlayWiring {

	@Override
	public void Play() {
		// TODO Auto-generated method stub
		System.out.println("I play!!");
	}

	@Override
	public void Brand() {
		// TODO Auto-generated method stub
		System.out.println("Smartphone!!!");
	}

	@Override
	public void Model() {
		// TODO Auto-generated method stub
		System.out.println("vivo");
	}

	@Override
	public void Internet() {
		// TODO Auto-generated method stub
		System.out.println("I am online!!!");
	}

}



package phone;
/**
 * Implement the Playwiring interface while inheriting the Handest class
 * @author langlang
 *
 */
public class CommonHandset extends Handest implements PlayWiring {

	@Override
	public void Brand() {
		// TODO Auto-generated method stub
		System.out.println("Candy bar!!!");
	}

	@Override
	public void Model() {
		// TODO Auto-generated method stub
		System.out.println("Nokia!!!!");
	}

	@Override
	public void Play() {
		// TODO Auto-generated method stub
		System.out.println("I play!!");
	}

}





package phone;
/**
 * The abstract method can set the brand and model of the mobile phone to display the information of the brand and model of the mobile phone
 * @author langlang
 *
 */
public abstract class Handest {
public abstract void Brand() ;
public abstract void Model();
}





package phone;

public class Mymain {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
			CommonHandset c= new CommonHandset();
			c.Brand();
			c.Model();
			c.Play();
			System.out.println("---------------------------");
			AptiudeHandset a = new AptiudeHandset();
			a.Brand();
			a.Model();
			a.Play();
			to Internet();
	}

}






package phone;
/**
 * The interface has internet capability
 * @author langlang
 *
 */
public interface Network {
public void Internet();
}








package phone;
/**
 * The interface has playback capability
 * @author langlang
 *
 */
public interface PlayWiring {
public void Play();
}







package phone;
/**
 * The interface has the ability to take pictures,
 * @author langlang
 *
 */
public interface TheakePicTures {
public void Photo();
}

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325558043&siteId=291194637