wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Reg:- Interface internal Syntex. 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 "Reg:- Interface internal Syntex." Watch "Reg:- Interface internal Syntex." New topic
Author

Reg:- Interface internal Syntex.

RAGU KANNAN
Ranch Hand

Joined: Dec 16, 2005
Posts: 103
From the following question, The answer �A� and �E� are correct, But �B� is wrong the reason is non static inner class won�t allow static. So the interface J{} is internally static.
But the interface are internally public abstract. I don�t know where the static modifier coming from, Pls advice me.

Thanks, Raghu.K

Question:-
Which of the following will not cause compilation errors if inserted at line 6?
class TestInner{ //1
private static int i = 10; //2
private static void f(){System.out.println(i);}//3
TestInner(){System.out.print("Outer");}//4
class MyInner{//5
//6 insert code here
MyInner(){System.out.print("Inner"+i);}//7
void g(){f();}
}
public static void main(String args[]){
new TestInner().new MyInner();
}
}

Answer :-
A) class I{}
B) interface J{}
C) static class I{}
D) static Interface J{}
E) final Integer I=new Integer(10);
Praveen Babu
Ranch Hand

Joined: Jul 30, 2006
Posts: 138
Hi,

Inner Interfaces are static by default. To see this,

Try,



Observe that line 1 will not compile while line 2 compiles

Regards,
Praveen
[ September 04, 2006: Message edited by: Praveen Babu ]
Mani Venkata Kanth
Ranch Hand

Joined: Aug 21, 2006
Posts: 39
hi
we have static member,non-static member,local and anonymous classes.
but we have only static member interfaces. there are no non-static member ,local,anonymous interfaces.

And by default innner interfaces are static.
NO need to declare an interface as a static.

Better refer chapter 7 in khalid mughal book.

I think your doubt cleared ..
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Raghu, when you use the word "internally" above, do you mean "implictly"?
That is: a nested inteface is implicitly static. So:


The above is the same as


In both cases you can access interface I without an instance of class A as in



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

Joined: Aug 03, 2002
Posts: 7729
If you now try this:


you will find that you get a compilation error to the effect of B cannot have a static member. That's because I is implicitly static in B. The inner class B cannot contain any static members.

Now, if we make B a static nested class:



You will now find that it compiles and Z can implement I via A and B.
[ September 05, 2006: Message edited by: Barry Gaunt ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reg:- Interface internal Syntex.