• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

can interface declare.....???

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Frndz,
can interface declare in local inner class?? coz i try to do this give me compile time error why??

thanx
Aftab Abbasi
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not?? Try this code

Since methods inside an interface cannot have a body, you will not be able to declare innerclasses within methods inside the interface. Top level classes are permitted and legal.
Ajith
 
Aftab Ahmed
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx Ajith u help me, and onething more can local inner class declare interface if yes plz give any example
thanx
Aftab Abbasi
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aftab,
The best tool to learn Java is the Java compiler itself( javac.exe ). Whenever you don't understand a concept, write code and play with it. Nothing helps you more than hands-on learning experience.
Having said that, why don't you try to compile the following program and see what happens.

Good luck,
Ajith
 
Aftab Ahmed
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Aijth,
thanx help me and give example code also. but your last code dosn't complie and give following error which given belown.
Outer.java:5: Member interfaces can only occur in interfaces
and op-level classes.
interface IFaceInInnerClassScope
^
Outer.java:10: Member interfaces can only occur in interfaces
and top-level classes.
IFaceInLocalInnerClassScope
^
2 errors
hope u tell me about this
thanx
Aftab
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Aftab,
You posted an interresting topic.
Now to your question.
As you may be knowing there are four types of nested classes/interfaces possible in Java.
*) Top-level nested class/interface.
*) Non-static class.
*) Local class.
*) Anonymous class.
The top-level classes are the static classes defined inside another class.
All the nested interfaces are by default static . meaning there's no thing like non-static interface or local interface defined inside a method.
So the compiler says just that.
Refer Khalid for more information.


------------------
Regards
---------
vadiraj

*****************
There's a lot of I in J.
*****************
 
Aftab Ahmed
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx vadiraj vd for help
Aftab Abbasi
 
Your mother was a hamster and your father was a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic