摘要:
try{}catch(异常名 接受异常){输出接受的异常}catch(异常名2 接受2){输出2} public class Demo07Exception { public static void main(String[] args) { String s="a.txt"; try { add( 阅读全文
posted @ 2024-06-24 23:00
DemoLiQi
阅读(23)
评论(0)
推荐(0)
摘要:
try_catch使用不影响其他功能的使用 这点比无脑throws强 public class Demo06Exception { public static void main(String[] args){ String s="a.txt"; try{ add(s); } catch (File 阅读全文
posted @ 2024-06-24 22:51
DemoLiQi
阅读(17)
评论(0)
推荐(0)
摘要:
将异常一层层往上抛,相当于模拟jvm操作,但是导致其他功能都无法使用,所以开发中无法一直throws 如果造成的异常存在异常子父类关系 只用抛出父类异常就可以 比如FileNotFoundException,IOException异常,FileNotFoundException是IOExceptio 阅读全文
posted @ 2024-06-24 22:10
DemoLiQi
阅读(19)
评论(0)
推荐(0)
摘要:
public class Demo03Exception { public static void main(String[] args) { String s="a.txt";//修改txt为t1xt就能正常运行 不修改以txt结尾就会进if抛出异常 method(s); } public sta 阅读全文
posted @ 2024-06-24 21:44
DemoLiQi
阅读(31)
评论(0)
推荐(0)
摘要:
public class Demo01Exception { public static void main(String[] args) { method(); //运行时期异常 int[] arr=new int[3]; System.out.println(arr[4]); //编译时期异常 阅读全文
posted @ 2024-06-24 21:27
DemoLiQi
阅读(38)
评论(0)
推荐(0)
摘要:
 阅读全文
posted @ 2024-06-24 20:50
DemoLiQi
阅读(29)
评论(0)
推荐(0)
摘要:
  
评论(0)
推荐(0)
摘要:
public interface USB { public void open(); } public class Test { public static void main(String[] args) { method( new USB(){ @Override public void ope 阅读全文
posted @ 2024-06-24 20:26
DemoLiQi
阅读(12)
评论(0)
推荐(0)
摘要:
所谓匿名内部类.可以理解为没有显式声明出来的内部来 问题描述:我们如果想调用接口里的方法或者继承抽象类里的变量.就要创建一个实现类来实现接口重写方法等还要new对象调用, 如果只是简单想使用一次接口里的方法,如何变得不麻烦 a.创建实现类 b实现接口,重写方法 c创建实现类对象 d调用方法 如果单纯 阅读全文
posted @ 2024-06-24 20:13
DemoLiQi
阅读(20)
评论(0)
推荐(0)
摘要:
public class Test { public static void main(String[] args) { USB usb= method();//USB usb= new Mouse;多态 //定义一个局部内部类 } public static USB method() { clas 阅读全文
posted @ 2024-06-24 19:35
DemoLiQi
阅读(21)
评论(0)
推荐(0)

浙公网安备 33010602011771号