• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

interface  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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.

I am having doubt in this question.
I think it is not necessary to declare class as public and static in interface.but its answer is 2,3&4.
can anyone explain the answer.
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


1. it is not possible in the java Laungage.



Well this is false for a very simple reason. It is possible to declare a class inside an interface declaration.


2. The class is always public.



True, all interface members (fields, methods and classes) are public whether you declare them that way or not. If you omit the public keyword they are declared public anyway.


3. The class is always static.



Declaring a field member in a interface makes it public and static by default. It is the same thing with a class declaration. It is static by default. Something very logical, since an interface by itself cannot be instantiated it would not make sense to declare a non-static inner class.


4. the class methods cannot call the methods declared in the interface.



What would be the point, the interface must be implemented in order to invoke one of the methods. So this is ultimately true.


5. the class methods can call only the static methods declared in the interface.



It is false, you cannot you can invoke other methods declared in the same class or other objects instantiated or passed by parameters to this class.
[ January 16, 2007: Message edited by: Edwin Dalorzo ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!