The basic of Java -- Abstract, Interface, Polymorphism, Inheritance, Wrap, Lambda(day 05)
2017-12-09 21:05
381 查看
1. Abstract class can realize methods, but interface only can define abstract and constant(before version 1.8), and then the following versions allow interface create static method.
2. Superclass can call the overried method of subclass, but not the overloading method.
3. From version 1.8, interface are able to have default method in order to let subclass extend and override. Additionally, if we tend to call the method of superclass, we should use
superclass.super.default method()
4. Polymorphism:
①upwards modeling: the class's superclass or implemented interface.
②dynamic binding: binding according with the object in runtime.
5.There need to cast when the big type converted in to small type, but if there is no connection between two types, we cannot convert them. Besides, throwing exception is common when we cast, in this way, using
instanceof is a effective way.
6. Inner class: mostly, inner classes are private, which are always serve for outer class, so if we want to call the inner class, we can new inner class in the constructor of outer class.
7. Anonymous inner class: sometimes, we only call a class's method one time, and when we create its object, we will not use it again. So in order to reduce
unnecessary trouble. we use anonymous.
parentheses:
add the formal parameters of method that wait to realize.
brace:
method body of method.
9. Lambda only are used in FunctionalInterface(the interface only have one abstract method beside Object)
example of Lambda:
2. Superclass can call the overried method of subclass, but not the overloading method.
3. From version 1.8, interface are able to have default method in order to let subclass extend and override. Additionally, if we tend to call the method of superclass, we should use
superclass.super.default method()
4. Polymorphism:
①upwards modeling: the class's superclass or implemented interface.
②dynamic binding: binding according with the object in runtime.
5.There need to cast when the big type converted in to small type, but if there is no connection between two types, we cannot convert them. Besides, throwing exception is common when we cast, in this way, using
instanceof is a effective way.
6. Inner class: mostly, inner classes are private, which are always serve for outer class, so if we want to call the inner class, we can new inner class in the constructor of outer class.
7. Anonymous inner class: sometimes, we only call a class's method one time, and when we create its object, we will not use it again. So in order to reduce
unnecessary trouble. we use anonymous.
Animal a = new Animal(){ @override public void run(){ //sentence } };8. Lambda: replace anonymous inner class: () - > {}
parentheses:
add the formal parameters of method that wait to realize.
brace:
method body of method.
Animal a = (a,b){return a+b;};
9. Lambda only are used in FunctionalInterface(the interface only have one abstract method beside Object)
example of Lambda:
Integer[] a = {1,3,2,5,4,6,7,9,8,0}; Arrays.sort(a); Arrays.toString(a); Arrays.sort(a, (o1,o2) -> {return o2 - o1;}); System.out.println(Arrays.toString(a));
相关文章推荐
- The basic of Java-Extends,Encapsulation,Abstract,Object,Singleton,Static(Day04)
- The basic of Java-Extends,Encapsulation,Abstract,Object,Singleton,Static(Day03)
- 【JavaLearning】接口与抽象类的比较(The comparison of Interface and Abstract Class )
- The step of installation of JDK and basic of JAVA(Day 01)
- [java] difference between Abstract Classes of Interface
- The second day of learning java
- Why do many Collection classes in Java extend the abstract class and implement the interface as well
- The first day of start learning Thinking in java
- The Week of Baidu Bugs - Day 05: 百度空间多处XSS漏洞
- The Interface and Class Hierarchy Diagram of Java Collections
- The first day of learn java
- C++.polymorphism.Simulation of JAVA's DB Interface
- A better understanding of java abstract class and interface
- What’s the difference between an interface and an abstract class in Java?
- Simple example of using the Java Native Interface
- The third day of learning java
- MapReduce报错:Error: java.io.IOException: Initialization of all the collectors failed. Error in last collector was :interface javax.xml.soap.Text
- The first day of learning java
- Simple example of using the Java Native Interface(JNI)
- PowerTip of the Day from powershell.com上周汇总(十)