71.如果一个类继承了一个抽象类,部分实现了该类的部分抽象方法,该类一定为抽象类吗?
一定
72.抽象类必须得有抽象方法存在
错
73.多态的表现方式?
多态在继承关系下,重写,重载,父类 引用对象 = new 子类();
接口 引用对象 =new 实现类();
74.接口和抽象类的区别
抽象类:可以有变量也可以有常量
可以有抽象方法也可以有实现方法
一个抽象类只能继承一个类,可以被多个类所继承
抽象类有构造方法
接口:只能有public static final修饰的常量,必须初始化赋值
只能有public abstract的抽象方法,没有实体方法存在
一个接口可以继承多个接口,一个类可以实现多个接口
接口没有构造方法
75.请列举常用的包、接口和类
包:java.lang 、java.util、java.io、java.text、java.sql、java.awt、javax.swing
类:String、ArrayList、Vector、HashMap、HashSet、DriverManager、SimpleDateFormat
Date、Thread
接口:Map、List、Set、Collection、Runnable、Connection、ResultSet、Statement、PreparedStatement
76.请列举常用的异常
ClassNotFoundException(类加载异常)、NullPointerException(空指针异常)、ArraysIndexOutOfBoundsException(数组下标越界异常)、SQLException(数据库操作异常)、IOException(IO流异常)、ArithmeticException(算术异常)、StringIndexOutOfBoundsException(字符串下标越界)。
77. class A extends Object{}
编译没有异常,因为Object是类的顶级类
78.try、catch是否可以单独使用
不可以
79.一个try可以接多个catch
可以
80.为何要捕捉异常
当程序发生异常时,捕捉异常可以绕过异常使程序继续执行
81.异常和错误的区别
异常:程序员可以判定并且编译时没有错误,运行时所产生的情况。例如除数为0
错误:程序员不能判定而产生的错误。例如内存溢出
82.编译能通过吗,输出结果
try{
System.out.print(“ok”);
}finally{
System.out.print(“hello”);
}
能通过编译。输出:okhello。这样不会捕捉异常
83.编译能通过吗
try{
int num1/0;
}catch(Exception e){
System.out.print(“1”);
}catch(NullPointerException e){
System.out.print(“2”);
}finally{
System.out.print(“3”);
}
编译有错误 应该把小范围的放在前面,大范围的放在后面
改正:try{
int num1/0;
}catch(NullPointerException e){
System.out.print(“1”);
}catch(Exception e){
System.out.print(“2”);
}finally{
System.out.print(“3”);
}
84.输出结果
try{
int num1/0;
}catch(NullPointerException e){
System.out.print(“1”);
}catch(Exception e){
System.out.print(“2”);
}finally{
System.out.print(“3”);
}
输出结果值:23
85.输出结果
try{
int num1/0;
}catch(ArithmeticException e){
System.out.print(“1”);
}catch(Exception e){
System.out.print(“2”);
}finally{
System.out.print(“3”);
}
输出结果值:13 返回值:12
86.输出结果:
public int show(){
try{
int num1/0;
return 10;
}catch(ArithmeticException e){
System.out.print(“1”);
}catch(Exception e){
System.out.print(“2”);
}finally{
System.out.print(“3”);
}
return12;
}
输出值:13
87. 输出结果
public int show(){
try{
int num1/1;
return10;
}catch(ArithmeticException e){
System.out.print(“1”);
}catch(Exception e){
System.out.print(“2”);
}finally{
System.out.print(“3”);
}
return12;
}
输出值:3 返回值:10
88.finally是否不管异常与否都执行
是在return之前执行
89.finally、final、finalize的区别
final:被final所修饰的类不能被继承、方法不能被重写、变量为常量为常量,必须初始化赋值,不能二次赋值
finally:用于异常处理,不管是否异常都执行,并且在return前执行
finalize:用于GC垃圾回收机制用于处理文件流读写未关闭等
90.throw和throws的区别
throw是程序员为了业务逻辑,手动抛出的异常
throws是方法上部抛出异常,本方法没有try catch语句块。不在该方法抛出异常,谁调用该方法,哪个方法就负责抛出异常
后续会持续更新,完整资源已经上传,记得关注免费下载哦!