The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes overriding a static method with non-static method? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "overriding a static method with non-static method?" Watch "overriding a static method with non-static method?" New topic
Author

overriding a static method with non-static method?

anamika sharma
Greenhorn

Joined: Oct 31, 2000
Posts: 5
The following code will give
1: class Test
2: {
3: static void show()
4: {
5: System.out.println("Static method in Test");
6: }
7: }
8: public class Q4 extends Test
9: {
10: void show()
11: {
12: System.out.println("Overridden static method in Q4");
13: }
14: public static void main(String[] args)
15: {
16: }
17: }A) Compilation error at line 3.
B) Compilation error at line 10.
C) No compilation error, but runtime exception at line 3.
D) No compilation error, but runtime exception at line 10.
Answer: B
But when i copied and pasted it and tried to run there was no compilation err. but runtime error
Help me!!

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Anamika,
I don't know which compiler you're using, but I tried it on the JDK1.3 compiler (javac) and got the following message:
<pre>C:\jdk1.3\projects\test1\Q4.java:10: show() in Q4 cannot override show() in Test; overridden method is static
void show()
^
1 error</pre>
Regards,
Beno�t
Jonathan Jeban
Ranch Hand

Joined: Oct 08, 2000
Posts: 52
Hi Anamika!
I got compilation error at line:10.(thats option B)
I am using jdk 1.2
Jeban
 
 
subject: overriding a static method with non-static method?
 
Threads others viewed
Method Overloading
regarding subclassing
Doubt in the code.
Question about Master Exam question (array usage)
Static Method Inheritance ??
developer file tools