aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes An anonymous inner class. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "An anonymous inner class." Watch "An anonymous inner class." New topic
Author

An anonymous inner class.

Dejan Miler
Ranch Hand

Joined: Nov 14, 2009
Posts: 56
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


SCJP 1.6 in progress ....
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
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

Joined: Nov 14, 2009
Posts: 56
I do not think that this is what is say.
But thanks you trying.

Dejan
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
why dont you try.....what have you understood?
Dejan Miler
Ranch Hand

Joined: Nov 14, 2009
Posts: 56
Interface cannot implements another interface

Dejan.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

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



SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
Dejan Miler
Ranch Hand

Joined: Nov 14, 2009
Posts: 56
Thanks guys.
I also had the same opinion like you.
but still i wanted to check

Dejan.
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
Dejan Miler
Ranch Hand

Joined: Nov 14, 2009
Posts: 56
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

Joined: Nov 25, 2009
Posts: 21



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

Joined: Aug 03, 2008
Posts: 9302
    
  17

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
 
subject: An anonymous inner class.