标签:extends 字符 sage 底层实现 city syn 执行 分配 super
public interface BaseService {
default void sayHello(){
System.out.println("helo");
}
}
public class BaseServiceImpl implements BaseService {
public static void main(String[] args) {
BaseService baseService = new BaseServiceImpl();
baseService.sayHello();
}
}
public interface BaseService {
void sayHello();
}
/**
* 默认实现抽象类
*/
public abstract class MyService {
public void sayHello(){
System.out.println("my hello");
}
}
public class BaseServiceImpl extends MyService implements BaseService {
public static void main(String[] args) {
BaseService baseService = new BaseServiceImpl();
baseService.sayHello();
}
}
public class MyException {
public static void main(String[] args) {
int s = testExcep();
System.out.println("返回值:"+s);
}
private static int testExcep() {
int a = 0;
try {
a = 9/0;
//return a; //返回值为9,去掉return ,a的值在finally 里被修改,如果finally 里有return则返回8,没有return 就在这里直接返回,除非产生异常,没有执行return
}catch (Exception e){
System.out.println(e.getMessage());
a= 7;
return a; //catch 里的return会 finally 里的return 挤掉
}finally {
System.out.println("执行");
a = 8;
//return a; //无论之前有没有return ,都会执行finally里的return;如果finally 里没有return ,这return 在哪,就返回最近的值;
}
return a;
}
}
Try(这里创建的对象自动关闭,比如inputStream.){..}catch{...}finally{释放资源}
@Override
public synchronized StringBuffer append(CharSequence s) {
toStringCache = null;
super.append(s);
return this;
}
底层实现是char[],初始容量16;
StringBuilder线程不安全,因为没加锁。
Charset charset = Charset.forName("utf-8");//import java.nio.charset.Charset;
[java基础]复习 java三大特性,异常,接口,String
标签:extends 字符 sage 底层实现 city syn 执行 分配 super
原文地址:https://www.cnblogs.com/ngLee/p/14033478.html