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 Question on Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on Interface" Watch "Question on Interface" New topic
Author

Question on Interface

majohnad majohnad
Greenhorn

Joined: Jan 01, 2003
Posts: 24
HI,
Which of the following statements are correct about interfaces?


1. Property fields in interface are automatically defined as public, static and final.
2. Property fields in interface are automatically defined as static and final only.
3. Properties defined in interface must contain uppercase characters.
4. Interfaces use the keyword implements to ensure multiple inheritance.
5. Classes implementing interface must implement each method defined in the interface.
what are the correct answers?


zxjohn
Praveen Kumar Mathaley
Ranch Hand

Joined: Apr 14, 2003
Posts: 45
option 1 is correct
option 5 is obviously correct
rest are incorrect
about option4 it's incorrect since Interfaces use keyword extends to ensure multiple inheritance
Rajeshwari Natarajan
Ranch Hand

Joined: Mar 05, 2003
Posts: 67
Originally posted by majohnad majohnad:

1. Property fields in interface are automatically defined as public, static and final.
2. Property fields in interface are automatically defined as static and final only.
3. Properties defined in interface must contain uppercase characters.
4. Interfaces use the keyword implements to ensure multiple inheritance.
5. Classes implementing interface must implement each method defined in the interface.
what are the correct answers?

only the first choice is correct.
5 is not correct . A class need not implement all the methods in the interface it implements, if it is declared abstract.
[ April 16, 2003: Message edited by: Rajeshwari Natarajan ]

regards<br />Rajeshwari. N
Prem Kumar
Greenhorn

Joined: Apr 02, 2003
Posts: 29
I agree with Praveen kumar's answer
Option 1 and 5 is correct.
Option 2,3,4 are incorrect.
Regards
PREM
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Only option 1 is correct
This compiles cleanly:
interface I {void m();}
abstract class C implements I {}


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Ryan Wilson
Ranch Hand

Joined: Apr 16, 2003
Posts: 65
Wont the exam explicitly state if the class is abstract?
So in this case option 5 should be correct also?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
abstact classes are classes as defined by the JLS so #5 is wrong. The question seems very specific to me. Must all classes that implement an interface implement all the methods of the interface. The answer is no. Only non-abstract classes must implement all the methods of an implemented interface.
Here is another example:
interface I { void m(); }
public class A { public void m() {} }
public class B extends A implements I {}
B does not need to directly implement the interface method since it inherited the implementation from A.
[ April 16, 2003: Message edited by: Thomas Paul ]
Praveen Kumar Mathaley
Ranch Hand

Joined: Apr 14, 2003
Posts: 45
Thanks Thomas for the correct explanation,
Indeed I agree that option 5 is wrong.
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Originally posted by Ryan Wilson:
Wont the exam explicitly state if the class is abstract?
So in this case option 5 should be correct also?

Howdy, yes the exam *would* explicitly state whether the class is abstract, and the exam would *not* word an answer the way #5 is worded, because that is too ambiguous. We tried very VERY hard with this exam to close off the possibilities for someone to say, "well, based on this premise, that answer IS correct, but based on this other premise, it is NOT correct..."
So, on the real exam, if this were a question, it would say something like,
"Any class implementing an interface, regardless of the class modifiers, MUST implement each method in the interface."
[very clearly false]
OR...
"A non-abstract class that implements an interface, must implement each method of the interface."
[true, and *almost* 100% clear]
OR...
"An abstract class that implements an interface must implement each method in the interface."
[very clearly false]
We weren't successful 100% of the time, in eliminating absolutely EVERY possible ambiguity, but it's very close.
If I could offer one big word of advice to anyone preparing, if you see a question on a mock exam with an answer that makes you say, "Well, it DEPENDS..." chances are, it is not a well-worded question. Or at least not up to the level of the actual exam.
Even the mock exams in our book, which are very close to the scope and style of the real exam, still contain some questions and answers that are a little more fuzzy than you would see on the exam (and fuzzier than we would have liked). We simply could not match the level of rigor (not to mention resources) put into the technical review process (and beta analysis) of the *real* exam.
So please don't panic when you see a lot of mock exam questions that are confusingly-worded. I would stick to the mock exams that are known to be quality mocks. I think that means Mughall's book, ours (of course , and although I haven't seen the newest rev of Bill and Marcus' Exam Cram, Marcus has had a reputation for many years (sheesh, I remember his from '98!) for having *excellent* questions.
Dan Chisholm's questions are obviously wonderful; I'm just putting them in a separate category if the issue is about knowing how the questions on the actual exam are likely to be worded.
cheers,
Kathy
John Zoetebier
Ranch Hand

Joined: Mar 28, 2003
Posts: 76
Kathy says:

Howdy, yes the exam *would* explicitly state whether the class is abstract, and the exam would *not* word an answer the way #5 is worded, because that is too ambiguous. We tried very VERY hard with this exam to close off the possibilities for someone to say, "well, based on this premise, that answer IS correct, but based on this other premise, it is NOT correct..."

After having done a lot of mock exams, ambiguity in answers has become a worry to me.
I am really happy to hear that the real exam has been tested to reduce ambiguity.
I did some mock exams lately where the "right" answers was not supported by the results of the compiler. Yet the test designer maintains that the answers are "right". Hmmmm ...
Talking about ambiguity: what is certain?
The term certain pops up everynow and then in answers to thread questions.
For example a thread program running 2 threads can have 2 outcomes, say A or B, but not both, depending on if the OS pre-emps one thread or an other.
We can now state:
a) Result A is not certain
Most people can agree that A is true, because the outcome could be either A or B.
However now we change the program slightly. The 2 threads are in an endless loop.
Can we still say that option a is true ?
Many people will say yes.
But from a mathematical point of view the answer is not as simple as it looks.
The reason is, that there is a non-zero probability that option 1 is true.
If we repeat the test an infinite number of times
the probability p that "A" will not happen is:
p * p * p * ... -> infinity
The limit of this change is zero.
Consequently, it is certain that result A will happen.
Hence option a is false.
The result is quite counter-intuitive to what most people think.
I now understand that this kind of ambiguity will not be on the exam, I hope, I pray
 
jQuery in Action, 2nd edition
 
subject: Question on Interface