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

class in interface!

 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the following are true about the class defined inside an interface ?
1) It is not possible in the java Laungage.
2) The class is always public.
3) The class is always static.
4) the class methods cannot call the methods declared in the interface.
5) the class methods can call only the static methods declared in the interface.
Answer:2,3,4.
hi! I didn't get the option 3 which says the class is always static. Is there any way to test it?
thanx.
ashok.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because an interface can't be instantiated, it is not possible for it to hold an inner(non-static) class that can only exist associated to an instance of the outer class.
This is the output of the followind program to javap where it can be seen the qualifier static:


C:\Java\TIJ2\Test>javap -c Test
Compiled from Test.java
public interface Test
/* ACC_SUPER bit NOT set */
{
public static class Test. Inner extends java.lang.Object
/* ACC_SUPER bit NOT set */
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ashok, see wheather ,following code helps you...
first define an Interface as follows-

Then try implementing this interface in some other class..

Hope it helps you.
Thanx
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic