aspose file tools*
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
Author

class declaration iside an interface

Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844

interface is implicitly abstract.but it allows to declare a class inside r it.like 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
Spring Tutorials, OCAJP Mock Questions, 400+ OCPJP Mock Questions
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Krishna,
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
Sheriff

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:
inter.Inner.method()
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: http://aspose.com/file-tools
 
subject: class declaration iside an interface