《java语言基础教程》p296
Console 是 final 类呀 怎么可以坐父类呢?
public class ShortStringReader extends Console { private final static int MAX = 10; public ShortStringReader() throws LongStringException{ // TODO Auto-generated constructor stub if(super.readString().length() <= MAX) return super.readString(); else throw new LongStringException("String to long. MAX:" + MAX); } }
p300
在Quotient()中已经catch到了ArithmeticException 干吗还throws 呢
public class Main { static void Quotient(int n, int d){// throws ArithmeticException { try { System.out.println(n/d); } catch (ArithmeticException e) { System.out.println(e); } } public static void main(String[] args) { int numer = 10; int denom = 0; Quotient(numer, denom); } }
本文探讨了Java中Console类作为final类时如何被继承的问题,并通过具体代码示例解析了异常处理机制,包括如何捕获与抛出异常。

被折叠的 条评论
为什么被折叠?



