I am learning the Exception handling in java (basically in inheritance)

前端 未结 4 955
刺人心
刺人心 2021-01-23 03:15

just look at program below..

import java.io.*;
import java.rmi.*;
class class1
{
  public void m1() throws RemoteException 
{
  System.out.println(\"m1 in class1         


        
4条回答
  •  -上瘾入骨i
    2021-01-23 03:28

    You can throw a more specific exception in an overidden method, but not a less specific one. RemoteException is a subclass of IOException, so class1 can throw IOException and class2 RemoteException but not the other way round.

提交回复
热议问题