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 class declaration iside an interface 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 "class declaration iside an interface" Watch "class declaration iside an interface" New topic

class declaration iside an interface

Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1850

interface is implicitly abstract.but it allows to declare a class inside r this,

above program will print Hai.
but it violates the abstract concept.
explain me.
[ Jess added UBB [code] tags to preserve whitespace, check 'em out! ]
[ August 07, 2003: Message edited by: Jessica Sant ]

Krishna Srinivasan
OCAJP 7/8 Exam, 400+ OCPJP Mock Questions
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Can you let me know which abstract concept is violating?
[ August 07, 2003: Message edited by: Andres Gonzalez ]

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

actually Krishna, how you have it written, it won't compile because of a couple reasons:
1- you've got a little typo in the name of your inner class -- it should be Inner not inner when you try to call it in your main() method.
2- you declared a non-static innter class so you have to instantiate the outer class in order to get access to the inner class. BUT as you know... you created the outer-class to be an interface.... so it can't be instantiated. That's why it won't compile -- this line won't work:
So, how do you fix it?
One option is to declare the inner class and its method to be static. That way you don't need to instantiate the outer class or the inner class in order to access the method.

The other option is to implement the interface, instantiate that new class, create an instance of the inner class and execute the method. How would you write the code to do it this way?

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
I agree. Here's the link:
subject: class declaration iside an interface
jQuery in Action, 3rd edition