File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Another one from Dan Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Another one from Dan" Watch "Another one from Dan" New topic

Another one from Dan

Saniya Ansari
Ranch Hand

Joined: Sep 30, 2002
Posts: 48
Question 8
interface C {
char w = DD.echo('w');
char x = DD.echo('x');
interface D extends C {
char y = DD.echo('y');
char z = DD.echo('z');
char a = DD.echo(w);
class DD implements D {
static char echo(char c) {
return c;
public static void main (String[] args) {
DD dd = new DD();

What is the result of attempting to compile and run the above program?
a. Prints: yzwMain
b. Prints: Mainyzw
c. Prints: wxyzwMain
d. Prints: Mainwxyzw
e. Prints: yzwxwwMain
f. Prints: Mainyzwxww
g. Runtime Exception
h. Compiler Error
i. None of the Above

The answer is D here.. i'm wondering why dont the interface variables get initialized unless explicitly called.. becoz interfaces are also implitly static and once they are loaded they should be intialized?? Whats the deal here!

Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Found it! Look here for a recent discussion of the same problem.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Does the other thread answer your question?
In short, Java tries to save time by only initializing what is needed.

Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="" target="_blank" rel="nofollow">Try my mock exam.</a>
I agree. Here's the link:
subject: Another one from Dan
It's not a secret anymore!