/**
* @author Administrator
*
* @description Interface Test class
* @history
*/
Interface interface{
public static final String INFO = "Helloeclipse";
public void print (); Defining methods
public abstract void Printinfo ();
}
Class I implements interface{
public void print () {
Method implementation
System.out.println (INFO); Helloeclipse
}
public void Printinfo () {
// ...
}
}
public class Interfacetestdemo {
/*** @description
* @param args
*/
public static void Main (string[] args) {
Interface interface
Interfaces interface and abstract classes cannot be instantiated directly and must be implemented by subclasses
New Interface () {
public void print () {
Anonymous inner class, method implementation
System.out.println (INFO); Helloeclipse
}
public void Printinfo () {
// ...
}
};
Interfaces are compared to abstract classes, and interfaces are more like a specification, abstract class, more like a template
Abstract classes Define some common implementations, and some of the methods that are not implemented are given to subclasses to implement specific functions-template methods
}
}
/**
* @author Administrator
*
* @description Abstract class Learning test class
* @history
*/
Abstract class abstract{//define Abstraction classes
Public final static String INFO = "Helloeclipse"; Defining Global variables/constants
Abstract public void print (); Defining abstract methods
Abstract classes cannot be instantiated directly, and subclasses of abstract classes must implement all abstract methods if they are not abstract classes.
}
Class Abstractzilei extends abstract{//defining abstract subclasses
public void print () {//Implement subclass method
System.out.println (INFO);
}
}
public class Abstracttestdemo {
/**
* @description
* @param args
*/
public static void Main (string[] args) {
Interfaces and abstract classes Interface,abstract
Abstract classes: Classes that contain abstract methods are called abstract classes.
New Abstract () {public void print () {
System.out.println (INFO); Anonymous abstract class implementation
}
};
Can abstract classes be finalized? The final definition of the class is the finalization class, the abstract class is required to implement the subclass
Final abstract class abstract{//...}/Compile Error
}
}
Dark Horse programmer-------Interface and abstract class