The basic of Java -- Abstract, Interface, Polymorphism, Inheritance, Wrap, Lambda(day 05)

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.

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));


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值