4 Replies Latest reply: Jul 5, 2011 8:53 AM by 872842 RSS

    OCJP

    872842
      Hi All,

      class A{
      public void process(){ S.o.p("A");
      }
      class B extends A{
      public void process() throws IOException{
      super.process();
      S.o.p("B");
      throw new IOException();
      }
      p s v m(String []args){
      try{(new B().process();)}
      catch(IOException e){ S.o.p("Exception");}
      }
      }

      result: compile time error in line "public void process() throws IOException"
      plz help me to find the reason.?

      regards ,
      Minuri...
        • 1. Re: OCJP
          798692
          Did you read my previous post correctly? Use code tag to post any codes.
          • 2. Re: OCJP
            EJP
            help me to find the reason?
            The reason is stated in the compiler error message. What part of it didn't you understand?
            • 3. Re: OCJP
              873158
              Here subclass B which extends from class A is overiding the method process(). While overiding you cannot declare a checked exceptions declaration in the subclass when you dont have any exception in the parent class. As per the contract of overiding you can have either have broader exceptions or no exceptions inherit from your parent class to your subclass.
              • 4. Re: OCJP
                872842
                Thank you v.much for Ur kind consideration... I got some idea.