Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

theortical questions

 
umesh rawat
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1 can we create Interface inside the class- if yes how
2 can we create class inside the interface - if yes how


Umesh Rawat
Rmw 2019
 
Anoobkumar Padmanabhan
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my knowledge, we can't create an interface within a class or class within an interface.

if anyone has an opinion yes, please let us know the details.
 
Aravind Jerubandi
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an interesting question. And as per my knowledge the answer is 'Yes' for both the questions.

In the 'Map' interface we have inner interface called 'Entry'. (which is a static interface by default)

Do not know of the example of inner class in an interface. But i think it can be created and it would static by default.
 
umesh rawat
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pleas somebody give the answers in the detail.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anoobkumar Padmanabhan:
In my knowledge, we can't create an interface within a class...

Why not?
 
Aravind Jerubandi
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, all the following four are possible:

1. class inside class (obvious )
2. interface inside interface
3. class inside interface
4. interface inside a class

Among all these, most of the times we use only inner classes.
 
Ravikanth kolli
Ranch Hand
Posts: 179
Chrome Eclipse IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are the classes within an interface declared final static?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Aravind Jerubandi:
So, all the following four are possible:
3. class inside interface

Can you give an example for that?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See JLS 6.4.3 - The Members of a Class Type...
The members of a class type (�8.2) are classes (�8.5, �9.5), interfaces (�8.5, �9.5), fields (�8.3, �9.3, �10.7), and methods (�8.4, �9.4).

And JLS 6.4.4 - The Members of an Interface Type...
The members of an interface type (�9.2) may be classes (�8.5, �9.5), interfaces (�8.5, �9.5), fields (�8.3, �9.3, �10.7), and methods (�8.4, �9.4).

[ October 20, 2008: Message edited by: marc weber ]
 
Aravind Jerubandi
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure why we use this. The following gets compiled fine.

 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is this question all about. You can create interface inside class, class inside interface etc.

@Ravikanth well classes inside interfaces are static but not final

Why is everyone looking for further explanation about this.. As everyone knows, there is no actual inner classes or interfaces. All inner classes and interfaces are converted into outer classes. It's just that by nesting a class or interface, you can keep a class that is needed by a method of a class inside that class. Arvind gives a good example for this.
 
Anoobkumar Padmanabhan
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You all for the responses.

i tried with inner classes and interfaces. Its working.
 
Ravikanth kolli
Ranch Hand
Posts: 179
Chrome Eclipse IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks ankit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic