• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Nested classes & Interface

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Everybody's invited. Even this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic