Originally posted by Jordi Marqu�s:
Hi!
This question if from mock of Sun web:
Which of the following methods would be legal (individually) at line 2 in class Test2?
Consider these classes, defined in separate source files:
1. public class Test1 {
2. public float aMethod(float a, float b)
throws IOException {
3. }
4. }
1. public class Test2 extends Test1 {
2.
3. }
A. float aMethod(float a, float b) { }
B. public int aMethod(int a, int b) throws Exception { }
C. public float aMethod(float a, float b) throws _Exception { }
D. public float aMethod(float p, float q) { }
The correct answer is B and D
I don�t understand why B is correct . Why B don�t return an int type?? Why can an int method override a float method???
Thank you in advance
Originally posted by Jordi Marqu�s:
Hi!
This question if from mock of Sun web:
Which of the following methods would be legal (individually) at line 2 in class Test2?
Consider these classes, defined in separate source files:
1. public class Test1 {
2. public float aMethod(float a, float b)
throws IOException {
3. }
4. }
1. public class Test2 extends Test1 {
2.
3. }
A. float aMethod(float a, float b) { }
B. public int aMethod(int a, int b) throws Exception { }
C. public float aMethod(float a, float b) throws _Exception { }
D. public float aMethod(float p, float q) { }
The correct answer is B and D
I don�t understand why B is correct . Why B don�t return an int type?? Why can an int method override a float method???
Thank you in advance
Muhammad Farooq<br />Sun Certified Programmer for Java 2 Platform<br />Oracle8i Certified Professional Database Administrator
Originally posted by Muhammad Farooq:
I just want to know why
C. public float aMethod(float a, float b) throws _Exception { }
is incorrect. _Exception can be a runtime exception or a subclass of runtime exception. AFAIK the overriding method can not throw any checked exception not thrown in overriden. Please correct me if I am wrong.
--Farooq
Muhammad Farooq<br />Sun Certified Programmer for Java 2 Platform<br />Oracle8i Certified Professional Database Administrator
Originally posted by Muhammad Farooq:
[..]should I always take it as checked exception if not stated/mentioned.[..]
If a regular clown is funny, then a larger clown would be funnier. Math. Verified by this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|