This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • 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:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

inner class in an Interface declaration

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can a nested class be declared in an Interface?
Question 15
Which of the follow are true statements.
a. A nested class is any class that is declared within the body of another class or interface.
b. A nested class can not be declared within the body of an interface declaration.
c. An inner class is a nested class that is not static.
d. A nested class can not be declared static.
e. A named class is any class that is not anonymous
The answers provided were a,c, & e - seems like the question is saying that b is 'true' since it is posed in a 'can not' formulation.
I can't create an example that compiles to prove that b should be true - any clarification most appreciated.
Thanks,
Doug
 
Ranch Hand
Posts: 330
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi doug. I think you can. see code below:

In the example above, since the nested class is enclosed within an interface, it becomes implicitly public and static.
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi doug,
A nested class can be declared within the body of an interface declaration. Here is a code snippet that I tried and compiles fine. Here class 'i' can be called an inner class because it is declared in an interface and I tried out class 'in' just for kicks:
public interface intCar
{
void drive();
class i
{
class in
{
void m()
{
System.out.println("m");
}
}
void m()
{
System.out.println("m");
}
}
}
ps: answers a and b negate each other so if a is true b has to be false
 
I want my playground back. Here, I'll give you this tiny ad for it:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!