Dark Horse programmer-------Interface and abstract class

Source: Internet
Author: User

/**
* @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

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.