aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Nested classes & Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Nested classes & Interface " Watch "Nested classes & Interface " New topic
Author

Nested classes & Interface

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
This code is from some book. I don�t remember the author.
interface MyInterface {
void method1();
void method2();
abstract class Abstract implements MyInterface {
public void method2() {
System.out.println("In method2");
}
}
}
I know that a class defined inside an interface is implicitly static.
What could be the reason this code not giving error as we cannot combine static as well as abstract.
Thanks
SathishVJ
Greenhorn

Joined: Sep 07, 2000
Posts: 16
Dilip,
It's not possible to combine final and abstract modifiers.
I don't think there is a problem in clubbing static and abstract in the class within the interface (top level static is not allowed). Try this:
...
static abstract class Abstract(){
...
It still works.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
static abstract class Abstract(){
The above code works perfectly. I think the cause of confusion was because an abstract method cannot be staic but an abstact inner class can.
The following will not compile
abstract class Myclass
{
public static abstract void show();
}
MyClass.java:3: Abstract methods can't be static: void show()
public static abstract void show();
^
1 error
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Nested classes & Interface
 
Similar Threads
sheer mind-searing frustration - arghh
deprecated interface methods
Need a Solution about the code given?
Explicit List implementation
class defined inside an interface