Demo01.java 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package J20250718.demo02_exception;
  2. /**
  3. * @author WanJl
  4. * @version 1.0
  5. * @title Demo01
  6. * @description
  7. * @create 2025/7/18
  8. */
  9. public class Demo01 {
  10. public static void method666(){
  11. method666(); //方法调用自身---方法的递归,方法调用自身层数太多就容易出现栈内存溢出错误
  12. System.out.println("hello......");
  13. System.out.println("hello......");
  14. System.out.println("hello......");
  15. System.out.println("hello......");
  16. }
  17. public static void main(String[] args) {
  18. //异常1-数组下标越界异常
  19. int[] arr=new int[3];
  20. //System.out.println(arr[4]); //ArrayIndexOutOfBoundsException
  21. //异常2-除零异常
  22. //System.out.println(5/0); //ArithmeticException
  23. //异常3-类型转换异常
  24. //Fu f=new Zi1();
  25. //Zi2 z2=(Zi2) f; //ClassCastException
  26. //int[] arr2=new int[1024*1024*1024]; //OutOfMemoryError
  27. method666(); //StackOverflowError
  28. }
  29. }
  30. class Fu{
  31. }
  32. class Zi1 extends Fu{
  33. }
  34. class Zi2 extends Fu{
  35. }