File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

An anonymous inner class.

 
Dejan Miler
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is for K&B book on page 684.


An anonymous inner class can extend one subclass or implement one interface. Unlike non-anonymous classes (inner or otherwise), an anonymous inner class cannot do both. In other words, it cannot both extend a class and implement an interface, nor can it implement more than one interface.


Can some one give me an example of that

Dejan
 
Ankur kothari
Ranch Hand
Posts: 531
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dude try creating an anonymous inner class that extends a class.....now one that implements an interface....

now one that does both.....can you do that?

interface PineApple
{
void m();
}

interface PineApple1
{
void m()1;
}

//inside a class
PineApple p=new PineApple() implements PineApple1
{
public void m()
{
System.out.println("a")
}
public void m1(){}
};

do you think this is possible?

i think this is what the statement says...i interpreted this way

 
Dejan Miler
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not think that this is what is say.
But thanks you trying.

Dejan
 
Ankur kothari
Ranch Hand
Posts: 531
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why dont you try.....what have you understood?
 
Dejan Miler
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interface cannot implements another interface

Dejan.
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dejan Miler wrote:I do not think that this is what is say.

The example given by Ankur is correct. Anonymous inner classes cannot implement or extend another class/interface

 
Ankur kothari
Ranch Hand
Posts: 531
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Dejan Miler
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys.
I also had the same opinion like you.
but still i wanted to check

Dejan.
 
Ankur kothari
Ranch Hand
Posts: 531
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Dejan Miler
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I knew that this is not legal

But I had thinking that there is something that I am missing here.
So I decide to ask you guys

Dejan
 
Folkert Meeuw
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Dejan Miler wrote:This is for K&B book on page 684.


An anonymous inner class can extend one subclass or implement one interface. Unlike non-anonymous classes (inner or otherwise), an anonymous inner class cannot do both. In other words, it cannot both extend a class and implement an interface, nor can it implement more than one interface.


Can some one give me an example of that

Dejan
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folkert welcome to javaranch.

Folkert, try to UseCodeTags when you post a source code. That way your code looks very good. Unformatted code is hard to read. You can add code tags by wrapping your code in [code] [/code] tags. You can edit your post using button...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic