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 Ambiguious Questions... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Ambiguious Questions..." Watch "Ambiguious Questions..." New topic
Author

Ambiguious Questions...

Shah Chunky
Ranch Hand

Joined: Dec 27, 2000
Posts: 116
Can someone tell me what to do when there are ambigious Questions in JCP
For E.x:-
Q.1) Which is the superclass of All Exceptions ?
a) Exception
b) Throwable
c) Error
d) Object
I m confused between Option (a) & (b).
Q.2) Can a Static method be Overridden or Not ? True/False
V all no that Static methods cannot be overridden to be Non-Static
But if above question comes in JCP then what should be the Answer.
Thanks.


Shah Chunky - Sun Certified Java2 Programmer.
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
From my experience, you're not going to find these ambiguous questions. You'll only find those on the mock exams. Throwable is at the top of the exception hierarchy. That's not ambiguous. A static method can be overidden. Try it for yourself.
Lam Thai
Ranch Hand

Joined: Apr 02, 2001
Posts: 117
Originally posted by Sean Casey:
From my experience, you're not going to find these ambiguous questions. You'll only find those on the mock exams. Throwable is at the top of the exception hierarchy. That's not ambiguous. A static method can be overidden. Try it for yourself.

Hi Sean,
In contrary to what you stated above, I learned that static method cannot be overridden. It can only be hidden.
'Overridden' implies dynamic/runtime binding, where the type of the instance or object will determine the method to be called.
While 'hidden' implies class binding, where the type of the class reference will determine the method to be called.
There is no rule that prevent you from providing static methods with same name and signatures/arguments for both subclass and superclass. But in doing so, you would not get polymorphism.
Here are the examples that show the differences.
overridden
class A { void foo() {System.out.println("A's foo");}}
class B extends A { void foo() {System.out.println("B's foo");}}
class C extends A { void foo() {System.out.println("C's foo");}}
public class Demo {
public static void main(String[] agrs) {
A[] my = {new B(), new C()}; for (int i = 0; i < my.length ; i++) {my[i].foo();}
}
}
print:
B's foo
C's foo

Hidden
class A { static void foo() {System.out.println("A's foo");}}
class B extends A { static void foo() {System.out.println("B's foo");}}
class C extends A { static void foo() {System.out.println("C's foo");}}
public class Demo {
public static void main(String[] agrs) {
A[] my = {new B(), new C()}; for (int i = 0; i < my.length ; i++) {my[i].foo();}
}
}
print:
A's foo
A's foo
Regards,
Lam

[This message has been edited by Lam Thai (edited May 13, 2001).]
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
Obviously it can't be used polymorphically since it is static. My only point is that you can use a static method with the same signature in a class that extends another class that has that same static method.
Lam Thai
Ranch Hand

Joined: Apr 02, 2001
Posts: 117
Originally posted by Sean Casey:
Obviously it can't be used polymorphically since it is static. My only point is that you can use a static method with the same signature in a class that extends another class that has that same static method.

In that case, the word 'overidden' might lead to misunderstanding since JLS associates method 'overridden' with 'polymorphism'.
The concepts of 'overriding', 'hiding', and 'shadowing' are very specific and different from each other and we must be very careful in using them else one might not maximize their SCJP score - not because s/he is ignorant of polymorphism but because s/he chooses the wrong definition.
- Lam -

[This message has been edited by Lam Thai (edited May 13, 2001).]
Ravindra Mohan
Ranch Hand

Joined: Mar 16, 2001
Posts: 216
Hi Folks,
Please refer to the folowing link. In java Hiding, Shadowing and
overriding are used in a different connotation. There is no scope for abguity out here.
http://www.javaranch.com/ubb/Forum24/HTML/009676.html
Lam has correcly understood the point made by Cindy..
Ravindra Mohan.

[This message has been edited by Ravindra Mohan (edited May 13, 2001).]
Lam Thai
Ranch Hand

Joined: Apr 02, 2001
Posts: 117
Originally posted by Ravindra Mohan:
Hi Folks,
Lam has correcly understood the point made by Cindy..
Ravindra Mohan.
[This message has been edited by Ravindra Mohan (edited May 13, 2001).]

Ravindra,
I only know what I know. I would not claim that I understood the point that Cindy made; Doing so is exagerated, conceded and simply myopic - Importantly that also shows my ignorance.
- Lam -
[This message has been edited by Lam Thai (edited May 13, 2001).]
Ravindra Mohan
Ranch Hand

Joined: Mar 16, 2001
Posts: 216
Lam,


I only know what I know. I would not claim that I understood the point that Cindy made; Doing so is exagerated, conceded and simply myopic - Importantly that also shows my ignorance.

I appreciate your candid approach, what I meant was that such a topic was discussed already in the javarach certification
forum and your point was in synch with the point made by
Cindy.
Ravindra Mohan.
Shah Chunky
Ranch Hand

Joined: Dec 27, 2000
Posts: 116
Dear Friends.
My Question Still remains ?
What i want to know from u guys is that what will be the answer for both the Questions ?
For Q.1) should i choose (b) i.e. Throwable
(Remember Exception is super class of all Exceptions)
Q.2) Should i choose False.
Thanks
Lam Thai
Ranch Hand

Joined: Apr 02, 2001
Posts: 117
Originally posted by Shah Chunky:
Dear Friends.
My Question Still remains ?
What i want to know from u guys is that what will be the answer for both the Questions ?
For Q.1) should i choose (b) i.e. Throwable
(Remember Exception is super class of all Exceptions)
Q.2) Should i choose False.
Thanks

Hi Shah,
#1. If you think All Exceptions include Exeception itself then Throwable is the choice. However since Throwable is an interface not a class; So from the spirit of the question accompanied by the keyword superclass, I would choose 'a' as my final answer.
#2. Definitely FALSE! You cannot override 'static' method.
- Lam -
[This message has been edited by Lam Thai (edited May 14, 2001).]
Shah Chunky
Ranch Hand

Joined: Dec 27, 2000
Posts: 116
Dear Lam...
Throwable is A Class & Not an Interface
So what do u think the answer would be ?
Thanks
Lam Thai
Ranch Hand

Joined: Apr 02, 2001
Posts: 117
Originally posted by Shah Chunky:
Dear Lam...
Throwable is A Class & Not an Interface
So what do u think the answer would be ?
Thanks

Hi Shah,
You are definitely right! What caused me to come up with such idea that Throwable is an interface? Shame is on me.
Now I have just gone through the inheritance tree and this is what I found:
Object <---Throwable <-----Error <--- { Exceptions you should not catch }
Object <---Throwable <----- Exception <--- { exceptions you can catch }
Based on that, I would say b) Throwable. If we choose either Exception or Error, we would miss half of the pie.
- Lam -
Ravindra Mohan
Ranch Hand

Joined: Mar 16, 2001
Posts: 216
Hi Folks,
The answer to the question is
1) Throwable is the super class of the all the exceptions.
2) Static methods cant be overriden.
Hope this clears the issue.
Ravindra Mohan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ambiguious Questions...