This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes theortical questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "theortical questions " Watch "theortical questions " New topic
Author

theortical questions

umesh rawat
Ranch Hand

Joined: Mar 03, 2007
Posts: 41
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


Umesh rawat <br />Rmw -2019

http://100javaquestions.blogspot.com
Anoobkumar Padmanabhan
Ranch Hand

Joined: Aug 08, 2007
Posts: 103
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.


Thanks<br /> <br />Anoobkumar<br />SCJP 1.5
Aravind Jerubandi
Ranch Hand

Joined: Dec 17, 2006
Posts: 49
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.


-Aravind<br />SCJP 5.0 (91%), Preparing for SCBCD.
umesh rawat
Ranch Hand

Joined: Mar 03, 2007
Posts: 41
pleas somebody give the answers in the detail.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Anoobkumar Padmanabhan:
In my knowledge, we can't create an interface within a class...

Why not?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Aravind Jerubandi
Ranch Hand

Joined: Dec 17, 2006
Posts: 49
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

Joined: Feb 10, 2008
Posts: 179

are the classes within an interface declared final static?


-kolli
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41634
    
  55
Originally posted by Aravind Jerubandi:
So, all the following four are possible:
3. class inside interface

Can you give an example for that?


Ping & DNS - my free Android networking tools app
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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

Joined: Dec 17, 2006
Posts: 49
I'm not sure why we use this. The following gets compiled fine.

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

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.


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Anoobkumar Padmanabhan
Ranch Hand

Joined: Aug 08, 2007
Posts: 103
Thank You all for the responses.

i tried with inner classes and interfaces. Its working.
Ravikanth kolli
Ranch Hand

Joined: Feb 10, 2008
Posts: 179

thanks ankit
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: theortical questions