File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question about overriding : from ExamLab practice test no 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question about overriding : from ExamLab practice test no 2" Watch "Question about overriding : from ExamLab practice test no 2" New topic
Author

Question about overriding : from ExamLab practice test no 2

Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446
    
    1

I encountered a question from Exam-Lab (truly a great learning tool) that is about overriding a method
the code is as follows


In K & B the exam watch is given that if a method throws a checked exception and the overriding method does not throw any exception then when we call the method from the subclass object but the superclass reference then the compiler complains because it thinks that it is calling the super type of the version (I understood it very well)
but in the above program
method in abstract class AbsA, the method throws a checked exception
this method is being overridden in abstract class AbsB (I found strange ...an abstract method overriding a non abstract method)
Now NonC extends AbsB and then it overrides play() method this time not throwing any exception
now in the main method of MC class we are using AbsA reference to call method play using the object NonC();
but I think this contradicts the rule that is given in K & Bt
this time the compiler does not think that the method getting called is from class AbsA
is it because we have declared it abstract?
or some other reason?
please help I am confused about this

SCJP 6 [86%], OCPWCD [84%], OCEJPAD [83%]
If you find any post useful, click the "plus one" sign on the right
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

but I think this contradicts the rule that is given in K & Bt
this time the compiler does not think that the method getting called is from class AbsA

How can you say this?? If you remove the throws clause from the main method, you'll get an error that you are not handling the InterruptedException...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446
    
    1

Ohh shit
could not notice that throws clause there
I thought that the exception is not handled there
my mistake ........

should give more attention to actually READING the questions well
another thing I wanted to say
I am getting about 50% to 55% marks in ExamLab
and after retaking the exam, means be thoroughly going through the concepts of the wrong questions... I am able to get about 80% (not by recalling the answer, by recalling the concepts and the solving the question once again ) in it
I think I am ready for the exam now
Ankit wish me luck for the exam
will take it on 30th June
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

Go for it, best of luck
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Best Wishes Prasad !!!

Do very Well !!! and do remember what your Dad says !!!



SCJP 6.0 96%

(Connecting the Dots ....)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question about overriding : from ExamLab practice test no 2