JAVA learning experience-Summary of JAVA Abstract classes and interfaces, java Abstraction
* -- Summarize JAVA Abstract classes and interfaces
* 1. abstract class:
* 1 abstract classes can be used to modify methods and classes, but cannot modify attributes or be instantiated.
* 2 abstract classes can be inherited. They can only be single-inheritance. abstract classes must implement abstract methods.
* 3 abstract classes cannot be modified together with static, fina, and private classes.
* 4. abstract classes have polymorphism.
*
* 2. interface:
* 1 "interface is a special abstract class and cannot be instantiated
* 2 the default attribute keyword stated by the interface is public abstract static.
* 3 the default keyword of the method stated in the interface is public abstract.
* 4 interfaces can be inherited. interfaces can be inherited or inherited.
* 5. The interface is polymorphism
*
Package come. java. zhangfan. test3; public class Test {public static void main (String [] args) {Students s = new Students (); t1 (s ); // output --- woshi Student T t = new T (); t (t);} // The public static void t1 (Person p) {p. T ();} // interface polymorphism public static void t (Runner p) {p. run (); // output--- woshi Run} // The application of the abstract class // The modifier for declaring abstract class Person {// field I is invalid; only "public", "protected", "private", "static", "final state", "transient", or "changeable" are allowed. // attributes cannot be overwritten // abstract int I; // The abstract Method T in the type Person can only set one of the visibility modifiers "public" or "protected" // if it is static, it means that you can directly call this method without creating an object, conflict With abstact // abstract static public void T (); // abstract method T of the type Person can only set one of the visibility modifiers "public" or "protected" // conflict with itself, do not explain // abstract final public void T (); // The abstract Method T in the type Person can only set the visibility modifier "public" or one of the "protected" // private methods cannot be overwritten // abstract private void T (); abstract public void T (); // True} // declare that a Student class inherits the abstract class and override the T method class Students extends Person {public void T () {System. out. println ("woshi Student") ;}// application interface Runner {public abstract void run () ;}interface timer mer {void swim ();} interface Flier {void fly () ;}// the interface can inherit interface t extends Runner, extends mer, flier {} // You must declare all inherited methods class t1 implements t {@ Override public void run () {// TODO automatically generated method stubs} @ Override public void swim () {// method stub automatically generated by TODO} @ Override public void fly () {// method stubs automatically generated by TODO} // The interface can be referenced multiple times. // all inherited methods must be affirmed. class T implements Flier, Runner, timer mer {@ Override public void fly () {// method stub automatically generated by TODO System. out. println ("woshi fly") ;}@ Override public void swim () {// TODO automatically generated method stub System. out. println ("woshi Swim") ;}@ Override public void run () {// method stub automatically generated by TODO. out. println ("woshi Run ");}}