• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about overriding : from ExamLab practice test no 2

 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go for it, best of luck
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best Wishes Prasad !!!

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

 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic