File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes R&H Second Edition SampleTestQ#40 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 » Mock Exam Errata
Bookmark "R&H Second Edition SampleTestQ#40" Watch "R&H Second Edition SampleTestQ#40" New topic
Author

R&H Second Edition SampleTestQ#40

jigneshk
Greenhorn

Joined: Jan 18, 2001
Posts: 1
40. Which of the following is/are true?
A. A static method may be overridden by a static method.
B. A static method may be overriden by a non-static method.
C. A non-static method may be overridden by a static method.
D. A non-static method may be overridden by a final non-static method.

My Answers are A ,D
Answers in the Book : D
Reason in book: A&B are false because static methods may not be overriden;
My sample to prove my answer is
import java.io.*;
class Test {
public static void trial() { System.out.println("Class Test");}
}
public class T extends Test
{
public static void trial() { System.out.println("Class T");}
public static void main (String[] args){
T t = new T();
t.trial();
}
}
The above code compiles and runs to print Class T....
Am I misinterpretting the answer?

Jignesh
Golam Newaz
Ranch Hand

Joined: Jan 08, 2001
Posts: 64
Hi,
You are right.
But i have a question about that?
Can you override public static void main(String[] argv)
method. Why main() method is always static? I think
it should clear our concept about static and non-static.
Thanks,
G. Newaz

nan sh
Ranch Hand

Joined: Jan 05, 2001
Posts: 167
But your sample code is noting to do with overriden.
overriden is that JVM will according to object type not
object reference type pick right method at running time
(not compiler time), all static method bind at compiler time( so as your sample
code)


Have you tried this Mock Exam Testing Engine yet?<br /><a href="http://www.mycgiserver.com/~nan111/index.html" target="_blank" rel="nofollow">www.mycgiserver.com/~nan111/index.html</a>
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
RHE is correct. You cannot override static methods, not with non-static methods and not with static methods.
If you try to override a static method with a non-static method you will get a compile time error.
If you try to override a static method with another static method it will compile and run, but it will not have the polymorphic behaviour that comes with overriding, thus you are hiding, not overriding. For example if you created an object like this:
Parent p = new Child();
Whenever you call non-static method like p.aMethod() it will first look for aMethod() in the Child class and then look in the Parent class if it is not in the Child class, that is overriding behaviour. But if you call a static method like p.aStaticMethod(); then it will only look in the Parent class.
This is an important point to remember.
Bill
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi jigneshk ...
Welcome to JavaRanch Please read our Name Policy and re-register with an appropriate name.
Thanks for your co-operation.

------------------

Jane Griscti
Sun Certified Java 2 Programmer
"When ideas fail, words come in very handy" -- Goethe


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: R&H Second Edition SampleTestQ#40